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.
please write a new program, and not what is on chegg they do not work correctly, a thumbs up will be given!
Four Files have been created
1. index.php : Display all six product with input for quantity
Input box are validated with only number
On submit form save.php called by post method
2. save.php : get parameter from index.php . Check if value exist for quantity the n added to session variable
3. confirm.php : Retrieve data from session and display if session value if exist
4. checkout.php : On check out logical order placed and session values are cleared
CODES
index.php
<html>
<head>
<script type =
'text/javascript'>
// ALLOW ONLY
INPUT TYPE NUMBER FOR ALL INPUT BOX , ON KEY PRESS EVENT
function
isNumberKey(evt)
{
var charCode =
(evt.which) ? evt.which : event.keyCode
if (charCode
> 31 && (charCode < 48 || charCode > 57))
return
false;
return
true;
}
</script>
</head>
<body>
<form action="save.php"
method="post" >
<table>
<tr><td width="150px"> Product Name
</td><td> Enter Nos </td>
</tr>
<tr><td> Mango </td><td>
<input type="text" onkeypress="return isNumberKey(event);"
name="mango"> </td>
</tr>
<tr> <td> Orange </td>
<td><input onkeypress="return isNumberKey(event);"
type="text" name="orange" > </td>
</tr>
<tr> <td> Banana </td>
<td><input onkeypress="return isNumberKey(event)"
type="text" name="banana" > </td>
</tr>
<tr> <td> Apple </td>
<td><input onkeypress="return isNumberKey(event)"
type="text" name="apple" > </td>
</tr>
<tr> <td> BlueBerry </td>
<td><input onkeypress="return isNumberKey(event)"
type="text" name="bluebery" > </td>
</tr>
<tr> <td> Cherries </td>
<td><input onkeypress="return isNumberKey(event)"
type="text" name="cherries" > </td>
</tr>
<tr>
<td> </td> <td>
<input type="submit" value="submit" name="submit" >
</td>
</table>
</form>
</body></html>
save.php
<?php
// RETRIEVE FROM POST DATA
$prod1 = $_REQUEST['mango'];
$prod2 = $_REQUEST['orange'];
$prod3 = $_REQUEST['banana'];
$prod4 = $_REQUEST['apple'];
$prod5 =
$_REQUEST['bluebery'];
$prod6 = $_REQUEST['cherries'];
//SESSION INVOKED
session_start();
// Storing session data
//IF PRODUCT FAVING QTY RECEIEVED
THE STORED IN SESSION FOR CORRESPONDING PRODUCT
if ($prod1!='')
$_SESSION["mango"] = $prod1;
if ($prod2!='')
$_SESSION["orange"] = $prod2;
if ($prod3!='')
$_SESSION["banana"] = $prod3;
if ($prod4!='')
$_SESSION["apple"] = $prod4;
if ($prod5!='')
$_SESSION["bluebery"] = $prod5;
if ($prod6!='')
$_SESSION["cherries"] = $prod6;
//CALL TO CONFIRMATION PAGE
header("Location: confirm.php");
exit;
?>
confirm.php
<html>
<?php
session_start();
//PRINT HEADER
echo "Products
Quantity <br>";
//PRINT PRODUCT NAME AND QTY IF
SESSION VALUE EXIST
if (
isset($_SESSION['mango']))
echo "Mango : "
. $_SESSION['mango'] . "<br>";
if (
isset($_SESSION['orange']))
echo "Orange : "
. $_SESSION['orange'] . "<br>";
if (
isset($_SESSION['banana']))
echo "Banana : "
. $_SESSION['banana'] . "<br>";
if (
isset($_SESSION['apple']))
echo "Apple : "
. $_SESSION['apple'] . "<br>";
if (
isset($_SESSION['bluebery']))
echo "Bluebery :
" . $_SESSION['bluebery'] . "<br>";
if (
isset($_SESSION['cherries']))
echo "Cherries :
" . $_SESSION['cherries'] . "<br>";
?>
<body>
<form action="checkout.php" method="post" >
<table>
<tr> <td><input
type="submit" value=" Check out " name="submit"
></td>
</table>
</form>
</body>
</html>
checkout.php
<html>
<head>
<?php
session_start();
//DESTORY THE SESSION ON CHECK OUT
session_destroy();
?>
</head>
<body>
Order Placed !
</body>
</html>
SCREEN SHOT
index.php

save.php

confirm.php

checkout.php

OUT PUT



Write a PHP program that displays an order form. The order form should list six products....