Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. $inventory = array('milk', 'cheese', 'bread', 'soda', 'weed');
  3.  
  4. if(isset($_POST['submit'])) {//if form is submitted
  5. if (!in_array($_POST['order_txt'], array_keys($inventory)))
  6. {
  7. //item # specified wasn't in the list
  8. }
  9. else
  10. {
  11. $_SESSION['items'][] = $inventory[$_POST['order_txt']];
  12. }
  13. }
  14.  
  15. var_dump($_SESSION);
  16.  
  17. echo "Welcome to Food Mart."."<br/><br/>";
  18.  
  19. echo "We carry the following items: "."<br/>";
  20. for($x=0; $x<sizeof($inventory); $x++){
  21. echo $x . ":" . $inventory[$x]."<br/>";
  22. }
  23. echo "<br/>";
  24. ?>
  25. <html>
  26. <body>
  27. <form action="<?php echo $PHP_SELF;?>" method="post">
  28. Number of Item: <input type="text" name ="order_txt" />
  29. <input type="submit" name="submit" value="Place Order"/>
  30. </form>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement