Write a PHP program that displays an order form. The order form should list six
ID: 3604940 • Letter: W
Question
Write a PHP program that displays an order form. The order form should list six products. Next to each product name there should be a text box into which a user can enter how many of that product she wants to order. When the form is submitted, the submitted form data should be saved into the session. Make another page that displays the order confirmation page which displays the contents of the saved order and a link to Check Out. When the Check Out link is clicked, the order should be cleared from the session.
Explanation / Answer
<html>
<body>
<h1>Enter The Quantity</h1>
<?php
//You need to make a file with name form.php and save this code in it
if(isset($_POST['Product1']) and isset($_POST['Product2']) and isset($_POST['Product3']) and isset($_POST['Product4']) and isset($_POST['Product5']) and isset($_POST['Product6']) and isset($_POST['Submit'])) {
$var1=$_POST['Product1'];
$var1=$_POST['Product2'];
$var1=$_POST['Product4'];
$var1=$_POST['Product5'];
$var1=$_POST['Product6'];
$var2=$_POST['Submit'];
var_dump( $var1);
var_dump( $var2);
var_dump( $var3);
var_dump( $var4);
var_dump( $var5);
var_dump( $var6);
}
//to change the the name of the products You can change the headings from <td>Product1<td> to <td>whateveryoulike<td> same goes for display.php
?>
<form action="display.php" method="post">
<table>
<tr>
<td>Product1</td>
<td><input type="text" name="Product1" id='Product1' required/></td>
</tr>
<tr>
<td>Product2</td>
<td><input type="text" name="Product2" id='Product2' required/></td>
</tr>
<tr>
<td>Product3</td>
<td><input type="text" name="Product3" id='Product3' required/></td>
</tr>
<tr>
<td>Product4</td>
<td><input type="text" name="Product4" id='Product4' required/></td>
</tr>
<tr>
<td>Product5</td>
<td><input type="text" name="Product5" id='Product5' required/></td>
</tr>
<tr>
<td>Product6</td>
<td><input type="text" name="Product6" id='Product6' required/></td>
</tr>
</table>
<input type="Submit" value="Submit" id='Submit'/>
</form>
</body>
</html>
/*Code above this line needed to be saved in one file with name form.php and code below this line need to be saved in another file with name display.php*/
<html>
<body>
<h1>Your Order</h1>
<?php
//You need to make file display.php and save this code in it
if(isset($_POST['display'])) { //check null
$var2 = $_POST['display'];
}
$var1 = $_POST['Product1'];
$var2 = $_POST['Product2'];
$var3 = $_POST['Product3'];
$var4 = $_POST['Product4'];
$var5 = $_POST['Product5'];
$var6 = $_POST['Product6'];
echo 'Product1 : ';
echo $var1."<br><br>";
echo 'Product2 : ';
echo $var2."<br><br>";
echo 'Product3 : ';
echo $var3."<br><br>";
echo 'Product4 : ';
echo $var4."<br><br>";
echo 'Product5 : ';
echo $var5."<br><br>";
echo 'Product6 : ';
echo $var6."<br><br>";
?>
<form action="form.php" method="post">
<input type="submit" id="display" name="display"><br /><br />
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.