i. Four 25-watt light bulbs for $2.39
ii. Eight 25-watt light bulbs for $4.29
iii. Four 25-watt long-life light bulbs for $3.95
iv. Eight 25-watt long-life light bulbs for $7.49
c. A collection of three radio buttons that are labeled as follows:
i. Visa
ii. Master Card
iii. Discover
<!DOCTYPE html>
<!–– bulbs.html
ordering bulbs
––>
<html lang = "en">
<head> <title> Ordering bulbs online </title> <meta charset = "utf-8" />
</head>
<body>
<h2> LightUpYourLife.com </h2>
<p>
<html lang="en"><head>
<title> Vegeta's Light Bulb Ordering Layout</title>
<meta charset="utf-8">
<body>
<p>
<label> <b>Customer Name:</b> <input name="Name" type="text"></label>
<br>
<br>
<br>
<b>Select your bulbs</b>
</p>
<p>
<label><input name="lights[]" value="4x25-watt" type="checkbox"> Four 25-watt light bulbs for $2.39 </label><br>
<label><input name="lights[]" value="8x25-watt" type="checkbox"> Eight 25-watt light bulbs for $4.29 </label><br>
<label><input name="lights[]" value="4x25-watt long-life" type="checkbox"> Four 25-watt light long-life bulbs for $3.95 </label><br>
<label><input name="lights[]" value="8x25-watt long-life" type="checkbox"> Eight 25-watt long-life light bulbs for $7.49 </label><br>
</p>
<b>Select your payment</b>
<p>
<label><input name="pmt" value="visa" type="radio"> Visa </label><br>
<label><input name="pmt" value="mastercard" type="radio"> Mastercard </label><br>
<label><input name="pmt" value="discover" type="radio"> Discover </label><br>
<label><input name="pmt" value="Paypal" type="radio"> Paypal </label><br></p>
<input value="Submit" type="submit">
<input value="Clear" type="reset">
<p></p>
</form>
</body></html>
9.10 Write a PHP script that computes the total cost of the ordered light bulbs from Exercise 9.9 after adding 6.2 percent sales tax. The program must inform the buyer of exactly what was ordered, in a table.
<!DOCTYPE html>
<!–– bulbs.html
ordering bulbs
––>
<html lang = "en">
<head> <title> Ordering bulbs online </title> <meta charset = "utf-8" />
</head>
<body>
<h2> LightUpYourLife.com </h2>
<p>
<html lang="en"><head>
<title> Vegeta's Light Bulb Ordering Layout</title>
<meta charset="utf-8">
<body>
<p>
<label> <b>Customer Name:</b> <input name="Name" type="text"></label>
<br>
<br>
<br>
<b>Select your bulbs</b>
</p>
<p>
<label><input name="bulb[]" value="4x25-watt" type="checkbox"> Four 25-watt light bulbs for $2.39 </label><br>
<label><input name=" bulb[]" value="8x25-watt" type="checkbox"> Eight 25-watt light bulbs for $4.29 </label><br>
<label><input name=" bulb[]" value="4x25-watt long-life" type="checkbox"> Four 25-watt light long-life bulbs for $3.95 </label><br>
<label><input name=" bulb[]" value="8x25-watt long-life" type="checkbox"> Eight 25-watt long-life light bulbs for $7.49 </label><br>
</p>
<b>Select your payment</b>
<p>
<label><input name="pmt" value="visa" type="radio"> Visa </label><br>
<label><input name="pmt" value="mastercard" type="radio"> Mastercard </label><br>
<label><input name="pmt" value="discover" type="radio"> Discover </label><br>
<label><input name="pmt" value="Paypal" type="radio"> Paypal </label><br></p>
<input value="Submit" type="submit">
<input value="Clear" type="reset">
<p></p>
</form>
</body></html>
<?php
//creating an array list of the cost of the bulb
$bulbs = array (
'Four 25- watt light bulbs' => 2.39,
'Eight 25- watt light bulbs' => 4.29,
'Four 25- watt long- life light bulbs' => 3.95,
'Eight 25- watt long- life light bulb' => 7.49,
);
$total = 0;
if(isset($_POST['submit'])) {
$bulb = $_POST["bulb"];
$how_many = count($bulb);
echo 'bulbs chosen: '.$how_many.'<br><br>';
if ($how_many>0) {
echo 'You chose the following bulbs:<br>';
}
//displaying selected bulb
for ($i=0; $i<$how_many; $i++) {
echo ($i+1) . '- ' . $bulb[$i] . '<br>';
// Create the beginning of HTML table, and of the first row
$html_table = '<table border="1 cellspacing="0" cellpadding="2""><tr>';
$nr_col = 1; // Sets the number of columns
$html_table .= '<td>' .$bulb[$i] . '<br>' . '</td>'; // adds the value in column in table
$html_table .= '</tr></table>'; // ends the last row, and the table
}
//computing the sum of the bulb selected
foreach($_POST['bulb'] as $bulb) {
if(array_key_exists($bulb, $bulbs))
$total += $bulbs[$bulb];
$totaltax=6.2/100*$total;
$totalcost=$total+$totaltax;
echo "The total cost is: ".$totalcost;
}
}
?>
</body>
</html>