Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Online Pizza Ordering Page</title>
  5. <link rel="stylesheet" type="text/css" href="mystyle.css">
  6. </head>
  7. <body>
  8. <h1>Online Pizza Ordering Page</h1>
  9. <a href="Detailedsauceandquantitypage.php?pizza=supreme">
  10. <img src="supreme.jpg" width="82" height="86" title="Supreme"
  11. alt="Supreme">
  12. </a>
  13. <a href="Detailedsauceandquantitypage.php?pizza=meatlover">
  14. <img src="meatlover.jpg" width="82" height="86"
  15. title="Meatlover" alt="Meatlover">
  16. </a>
  17. <a href="Detailedsauceandquantitypage.php?pizza=hawaii">
  18. <img src="hawaii.jpg" width="82" height="86" title="Hawaii"
  19. alt="Hawaii">
  20. </a>
  21. <a href="Detailedsauceandquantitypage.php?pizza=fourseasons">
  22. <img src="fourseasons.jpg" width="82" height="86" title="Four
  23. Seasons" alt="Four Seasons">
  24. </a>
  25. <a href="Detailedsauceandquantitypage.php?pizza=vege">
  26. <img src="vege.jpg" width="82" height="86" title="Vege"
  27. alt="Vege">
  28. </a>
  29. </body>
  30. </html>
  31.  
  32. <!DOCTYPE html>
  33. <html>
  34. <head>
  35. <script src="script.js"></script>
  36. <title>Detailed sauce and quantity page</title>
  37. <link rel="stylesheet" type="text/css" href="mystyle.css">
  38. </head>
  39. <body>
  40. <h1>Detailed sauce and quantity page</h1>
  41. <form action="ShoppingCartpage.php" method="POST">
  42. <!-- set form value to retrieve and pass the selected pizza to
  43. the cart -->
  44. <input type="hidden" name="pizza" value="<?php echo
  45. htmlspecialchars($_GET['pizza'], ENT_QUOTES, 'UTF-8', false); ?>">
  46. <img src="bbq.jpg" alt="BBQ">
  47. <label for="numberOfSauces">Number of Pizzas (0-100):</label>
  48. <input type="number" name="bbqPizza" min="0" max="100"
  49. value="0">
  50. <br>
  51. <img src="tomato.jpg" alt="Tomato">
  52. <label for="numberOfSauces">Number of Pizzas (0-100):</label>
  53. <input type="number" name="tomatoPizza" min="0" max="100"
  54. value="0">
  55. <br>
  56. <img src="salsa.jpg" alt="Salsa">
  57. <label for="numberOfSauces">Number of Pizzas (0-100):</label>
  58. <input type="number" name="salsaPizza" min="0" max="100"
  59. value="0">
  60. <br>
  61. <input type="submit" value="Add to cart" name="submit">
  62. <br>
  63. </form>
  64. </body>
  65. </html>
  66.  
  67. <?php
  68.  
  69. if (!session_id()) {
  70. //initialize the session if it is not already
  71. session_start();
  72. }
  73. if (!array_key_exists('pizzas', $_SESSION)) {
  74. //create initial storage of all pizzas
  75. $_SESSION['pizzas'] = [];
  76. }
  77. if (array_key_exists('submit', $_POST)) {
  78. if (!array_key_exists('pizza', $_POST)) {
  79. //a pizza was not selected, redirect the user back to the first
  80. page.
  81. }
  82. //determine sauce type quantities
  83. foreach(['bbqPizza', 'tomatoPizza', 'salsaPizza'] as $sauce) {
  84. //retrieve the quantity as an integer value
  85. if ($qty = filter_var($_POST[$sauce], FILTER_VALIDATE_INT)) {
  86. //add to the order only those that were selected
  87. //use a placeholder to store the quantity of sauce and
  88. pizza
  89. $key = $_POST['pizza'] . '_' . $sauce;
  90. if (!array_key_exists($key, $_SESSION['pizzas'])) {
  91. $_SESSION['pizzas'][$key] = [
  92. 'pizza' => $_POST['pizza'],
  93. 'sauce' => $sauce,
  94. 'qty' => 0
  95. ];
  96. }
  97. //increment the quantity of the pizza and sauce
  98. $_SESSION['pizzas'][$key]['qty'] += $qty;
  99. }
  100. }
  101. }
  102. if (empty($_SESSION['pizzas'])) {
  103. //no pizzas were added redirect to the first page.
  104. }
  105. ?>
  106. <!DOCTYPE html>
  107. <html>
  108. <head>
  109. <title>Shopping Cart page</title>
  110. <link rel="stylesheet" type="text/css" href="mystyle.css">
  111. </head>
  112. <body>
  113. <ol>
  114. <?php if (!empty($_SESSION['pizzas'])) {
  115. foreach($_SESSION['pizzas'] as $pie) { ?>
  116. <li>
  117. <?php printf('%s %s pizzas with %s sauce', $pie['qty'],
  118. $pie['pizza'], $pie['sauce']); ?>
  119. </li>
  120. <?php }
  121. } ?>
  122. </ol>
  123. <br>
  124. <a href="OnlinePizzaOrderingPage.html">Add more pizzas to cart</a>
  125. <a href="Checkoutpage.html">Go to checkout</a>
  126. </body>
  127. </html>
  128.  
  129. <!DOCTYPE html>
  130. <html>
  131. <head>
  132. <title>Checkout page</title>
  133. <link rel="stylesheet" type="text/css" href="mystyle.css">
  134. </head>
  135. <body>
  136. <h1>Checkout page</h1>
  137. <form action="Confirmationpage.php" method="POST">
  138. <input type="text" name="fName" placeholder="First Name"><br>
  139. <input type="text" name="lName" placeholder="Last Name"><br>
  140. <input type="email" name="email" placeholder="Email"><br>
  141. <input type="number" name="phoneNumber" placeholder="Phone Number">
  142. <br>
  143. <input type="submit" value="Confirm" name="submit">
  144. </form>
  145. </body>
  146. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement