我正在建立一个新的在线比萨订购网站,并希望在我的Web应用程序中显示用户的订单。如何合并会话代码,以便可以在ShoppingCartpage.php上输出用户的订单?
我尝试使用php,html,javascript和sql。
OnlinePizzaOrderingPage.php
<!DOCTYPE html>
<html>
<head>
<title>Online Pizza Ordering Page</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<?php
session_start();
$pizzas = array("supreme", "meatlover", "hawaii",
"fourseasons","vege");
$amounts = array("19.95", "19.95", "16.95", "22.95", "15.95");
if ( !isset($_SESSION["total"]) ) {
$_SESSION["total"] = 0;
for ($i=0; $i< count($pizzas); $i++) {
$_SESSION["qty"][$i] = 0;
$_SESSION["amounts"][$i] = 0;
}
}
if ( isset($_GET["add"]) ){
$i = $_GET["add"]{
$qty = $_SESSION["qty"][$i] + 1;
$_SESSION["amounts"][$i] = $amounts[$i] * $qty;
$_SESSION["cart"][$i] = $i;
$_SESSION["qty"][$i] = $qty;
}
?>
<h1>Online Pizza Ordering Page</h1>
<a href="Detailedsauceandquantitypage.php?pizza=supreme">
<img src="supreme.jpg" width="82" height="86" title="Supreme"
alt="Supreme">
</a>
<a href="Detailedsauceandquantitypage.php?pizza=meatlover">
<img src="meatlover.jpg" width="82" height="86"
title="Meatlover" alt="Meatlover">
</a>
<a href="Detailedsauceandquantitypage.php?pizza=hawaii">
<img src="hawaii.jpg" width="82" height="86" title="Hawaii"
alt="Hawaii">
</a>
<a href="Detailedsauceandquantitypage.php?pizza=fourseasons">
<img src="fourseasons.jpg" width="82" height="86" title="Four
Seasons" alt="Four Seasons">
</a>
<a href="Detailedsauceandquantitypage.php?pizza=vege">
<img src="vege.jpg" width="82" height="86" title="Vege"
alt="Vege">
</a>
</body>
</html>
ShoppingCartpage.php
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart page</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>Shopping Cart page</h1>
<?php
// define variables and set to empty values
$bbqPizza = $tomatoPizza = $salsaPizza = "";
if ( isset( $_POST['submit'] ) ) {
$pizza = $_POST['pizza']; //value from first page
$bbq = $_POST["bbqPizza"];
$tomato = $_POST["tomatoPizza"];
$salsa = $_POST["salsaPizza"];
echo $bbq . " " . $pizza . " pizzas with bbq sauce, " .
$tomato . " " . $pizza . " pizzas with tomato sauce and " . $salsa . "
" . $pizza . " Spizzas with salsa sauce.";
}
?>
<br>
<a href="OnlinePizzaOrderingPage.html">Add more pizzas to cart</a>
<a href="Checkoutpage.html">Go to checkout</a>
</body>
</html>
Detailedsauceandquantitypage.php
<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
<title>Detailed sauce and quantity page</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>Detailed sauce and quantity page</h1>
<form action="ShoppingCartpage.php" method="POST">
<!-- set form value to retrieve and pass the selected pizza to
the cart -->
<input type="hidden" name="pizza" value="<?php echo
htmlspecialchars($_GET['pizza'], ENT_QUOTES, 'UTF-8', false); ?>">
<img src="bbq.jpg" alt="BBQ">
<label for="numberOfSauces">Number of Pizzas (0-100):</label>
<input type="number" name="bbqPizza" min="0" max="100"
value="0">
<br>
<img src="tomato.jpg" alt="Tomato">
<label for="numberOfSauces">Number of Pizzas (0-100):</label>
<input type="number" name="tomatoPizza" min="0" max="100"
value="0">
<br>
<img src="salsa.jpg" alt="Salsa">
<label for="numberOfSauces">Number of Pizzas (0-100):</label>
<input type="number" name="salsaPizza" min="0" max="100"
value="0">
<br>
<input type="submit" value="Add to cart" name="submit">
<br>
</form>
</body>
</html>
我希望用户的订单显示在彼此下方。实际结果只是显示的是第一顺序,第二顺序将覆盖第一顺序...我希望第二顺序低于第一顺序。