Hello, I have run into an issue with and assignment. I am supposed to write an H
ID: 3801777 • Letter: H
Question
Hello,
I have run into an issue with and assignment. I am supposed to write an HTML form, which I have done and here it is pasted below:
<!DOCTYPE html>
<html lang = "en">
<head>
<h1>Light Bulb Order Form</h1>
</head>
<body>
<form method = "post">
<label> Name: <input type = "text" name = "myName" /> <br />
<br />
<label> <input type = "checkbox" name = "lights"
value = "four bulb" /> 25-watt light bulb for $2.39 </label><br />
<label> <input type = "checkbox" name = "lights"
value = "eight bulb" /> 40-watt light bulb for $4.29 </label><br />
<label> <input type = "checkbox" name = "lights"
value = "four ll bulb" /> 60-watt long-life light bulb for $3.95 </label> <br />
<label> <input type = "checkbox" name = "lights"
value = "eight ll bulb" /> 100-watt long-life light bulb for $7.49 </label> <br />
<br />
<label> <input type = "radio" name = "payment" value = "visa" checked = "checked" /> Visa <br/>
<label> <input type = "radio" name = "payment" value = "master card" checked = "checked" /> Master Card <br/>
<label> <input type = "radio" name = "payment" value = "discover" checked = "checked" /> Discover <br/>
<label> <input type = "radio" name = "payment" value = "check" checked = "checked" /> Check <br/>
<br />
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
==================================================
My issue is with the PHP side of this assignment where I need to handle the data in the form. I appreciate any help you can give. Here is the actual instruction on what needs to be done with the PHP::
Write a PHP script named lightbulbs.php to handle the data from the form described in lightbulbs.html that computes the cost of each product, the total number of items ordered, and the total cost of the order after adding 6.2% sales tax. The name, unit, price, number ordered, and total cost for each product are presented to the client in a table defined with interwoven html, but the contents of some of the data cells are defined with PHP.
Thank you in advance for your help.
Explanation / Answer
form_9.9.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Light Bulb Purchase Form</title>
<link rel="stylesheet" type="text/css" href="hw2.css" />
</head>
<body>
<h1>Welcome to the lightbulb page <img id="lightbulbPic" src="hw2 files/lightbulb.png" alt="picture of lightbulb" />
</h1>
<form method="post" name="lightbulb" action="form_9.10.php">
<fieldset>
<legend>Enter Your Name: </legend>
<label>Name:
<input type="text" name="user_name" />
</label>
</fieldset>
<fieldset>
<legend>Select Lightbulbs(You may select more than 1): </legend>
<label><input type="checkbox" name="option1" value="fourRegularBulb" />
4 x 25-watt light bulb for $2.39 <br/>
</label>
<label><input type="checkbox" name="option2" value="eightRegularBulb" />
8 x 25-watt light bulb for $4.29 <br/>
</label>
<label><input type="checkbox" name="option3" value="fourLongLifeBulb" />
4 x 25-watt long-life bulb for $3.95 <br/>
</label>
<label><input type="checkbox" name="option4" value="eightLongLifeBulb" />
8 x 25-watt long-life bulb for $7.49
</label>
</fieldset>
<fieldset>
<legend>Method of Payment</legend>
<label><input type="radio" name="paymentMethod" value="visa" checked="checked"/>
Visa
</label>
<label><input type="radio" name="paymentMethod" value="mastercard" />
MasterCard
</label>
<label><input type="radio" name="paymentMethod" value="discover" />
Discover
</label>
</fieldset>
<p>
<input id="submitButton" type="submit" value="Submit" />
</p>
</form>
<p>
<a href="http://validator.w3.org/check?uri=https://swe.umbc.edu/~kyongk1/is448/1119-kyongk1-hw2/form_9.9.html">
<img src="hw2 files/valid-xhtml11.png" alt="Valid HTML5" /></a>
<a href="http://jigsaw.w3.org/css-validator/validator?uri=https://swe.umbc.edu/~kyongk1/is448/1119-kyongk1-hw2/form_9.9.html">
<img src="hw2 files/vcss.gif" alt="Valid CSS" /></a>
</p>
</body>
</html>
<!--
a. A text widget to collect the user’s name
b. Four checkboxes, one each for the following items:
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
-->
form_9.10.php
<html>
<head>
<title>Computing Lightbulb Cost</title>
<link rel="stylesheet" type="text/css" href="hw2.css" />
</head>
<body>
<p>
<?php
$userName = $_POST["user_name"];
$fourRegular = $_POST["option1"];
$eightRegular = $_POST["option2"];
$fourLong = $_POST["option3"];
$eightLong = $_POST["option4"];
$payment = $_POST["paymentMethod"];
$total = 0;
$tax = 1.062;
if ((isset($userName) && (!empty($userName))))
{
if (preg_match("/^[A-zs]+$/", $userName))
{
if(!empty($lightbulbType_list))
{
if(!empty($payment))
{
echo "Thank you for your submission $userName<br />";
echo "Your payment method: $payment<br />";
foreach ($lightbulbType_list as $lightBulb){
$total += ($lightBulb * $tax);
echo "Prices of selected lightbulbs: $$lightBulb <br />";
}
echo "total price is $".round($total, 2)."<br />";
}
} else {
echo "Please make your lightbulb selection <br />";
?>
Please <a href="form_9.9.html">go back</a> and enter the required fields
<?php
}
} else {
echo "Only alphabetical characters allowed <br />";
?>
Please <a href="form_9.9.html">go back</a> and enter the required fields
<?php
}
} else {
echo "Please check your inputs and selections <br />";
?>
Please <a href="form_9.9.html">go back</a> and enter the required fields
<?php
}
?>
</p>
</body>
</html>
<!-- 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. -->
hw2.css
body {
background-color: #607D8B;
color: black;
font-family: Georgia, Garamond, serif;
margin: 10px auto 10px auto;
border: 10px #D8C858 solid;
}
h1 {
text-align: center;
}
fieldset {
padding: 10px;
margin: 10px;
border: 2px solid black;
}
legend, caption {
font-weight: bold;
}
table {
background-color: #9E9E9E;
margin: 10px auto 10px auto;
}
th, td {
text-align: left;
text-transform: uppercase;
border: 1px solid black;
}
th {
font-weight: bold;
}
#lightbulbPic {
height: 80px;
width: 15%;
}
#submitButton {
margin-left: 10px;
}
.endNote {
text-align: center;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.