Create an order.php page that will have a form, which takes in: a) Name (text) b
ID: 3764751 • Letter: C
Question
Create an order.php page that will have a form, which takes in:
a) Name (text)
b) Address (textarea)
c) 3 Items. Each item has 2 text input fields:
Item 1 : Name and Price
Item 2 : Name and Price
Item 3 : Name and Price
d) Discount: (select tag: “5%; 10%; 15%”) Submit value as 5, 10, or 15.
e) Submit button (“Place Order”)
Upon submission, the data is passed to a page called bill.php which processes the order. All amounts must be formatted to display as proper Saudi Riyal values, with SAR letters and correct precision.
bill.php does the following:
Calculate Total: = “Item 1 Price” + “Item 2 Price” + “Item 3 Price”
Calculate Discount: = Passed Discount / 100 ex: 10/100
Calculate Discount Amount = Total * Discount
Calculate Total Bill: = Total – (Discount Amount)
Displays the Name
Displays the address, with all the html tags stripped out.
Displays items ordered, Name and Price
Display Total price, Discount price, and the Discount Percent.
Display Total Bill.
Sample Output:
Name: Bob Smith
Ship To: 1 Main St. Toronto, Ontario
Order:
SAR 10.99 Radio
SAR 25.49 Ethernet Cable
SAR 45.99 USB Key
Summed Total: SAR 84.47
Discount: (15%) SAR 12.38
Bill Total: SAR 72.10
Explanation / Answer
order.php
<form name="form1" id="form1" method="post" action="bill.php">
Name <input name="name" maxlength="25" size="30" value="" type="text"> </br>
Address <textarea name="address"></textarea> </br>
Item 1 <input type="text" name="item1N"> <input type="text" name="item1P"> </br>
Item 2 <input type="text" name="item2N"> <input type="text" name="item2P"> </br>
Item 3 <input type="text" name="item3N"> <input type="text" name="item3P"> </br>
Discount
<select name="discount">
<option name="5"> 5% </option>
<option name="10"> 10% </option>
<option name="15"> 15% </option>
</select> </br>
<input name="submit" value="Place Order" type="submit">
</form>
bill.php
header("content-type: text/html; charset=UTF-8");
if(isset($_REQUEST['submit']))
{
$name=$_POST['name'];
$address=$_POST['address'];
$item1N=$_POST['item1N'];
$item1P=$_POST['item1P'];
$item2N=$_POST['item2N'];
$item2P=$_POST['item2P'];
$item3N=$_POST['item3N'];
$item3P=$_POST['item3P'];
$discount=$_POST['discount'];
$total = $item1P + $item2P + $item3P;
$discount = $discount/100;
$discount_price = $total * $discount;
$total = $total - $discount_price;
echo "Name : " . $name . "</br>";
echo "Ship To : " . strip_tags($address) . "</br>";
echo "Order : </br>";
echo json_decode('"ufdfc"') . " " . $item1P . " " . $item1N . "</br>";
echo json_decode('"ufdfc"') . " " . $item2P . " " . $item2N . "</br>";
echo json_decode('"ufdfc"') . " " . $item3P . " " . $item3N . "</br>";
echo "Summed Total : " . json_decode('"ufdfc"') . $total . "</br>";
echo "Discount : (" . $discount . "%)" . json_decode('"ufdfc"') . $discount_price . "</br>";
echo "Bill Total : " . json_decode('"ufdfc"') . $total . "</br>";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.