Write a script that reads the name of the car and displays the name of the company the car belongs to as per the below table:
Write a script that reads the name of the car and displays the
name of the company the car belongs to as per the below table:
PROGRAM
<!DOCTYPE html><html><head> <title>Car Company Finder</title></head><body>
<?php $car = $_POST['car']; $company = '';
switch ($car) { case 'Safari': case 'Nexon': case 'Tigor': case 'Tiago': $company = 'Tata'; break; case 'XUV700': case 'XUV300': case 'Bolero': $company = 'Mahindra'; break; case 'i20': case 'Verna': case 'Venue': case 'Creta': $company = 'Hyundai'; break; case 'Swift': case 'Alto': case 'Baleno': case 'Brezza': $company = 'Suzuki'; break; } ?>
<form method="post"> <label for="car">Enter Car Name:</label> <input type="text" name="car" id="car" value="<?php echo $car; ?>"> <input type="submit" value="Find Company"> </form>
<?php if (isset($car) && $company !== '') { echo "<p>$car belongs to $company</p>"; } ?>
</body></html>
OUTPUT
*If image are looking blur then click on the image for HD quality.
Explanation
This script takes in the name of a car through a form and uses a switch statement to determine which company the car belongs to based on the given table. The company name is then displayed on the page.
❤️ I Hope This Helps You Understand, Click Here To Do More Exercise In PHP Programming.