Advertisement
Guest User

Untitled

a guest
May 19th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4. <html>
  5. <head>
  6. <title> Choose toppings </title>
  7. <link rel="stylesheet" type="text/css" href="mystyle.css"/>
  8. </head>
  9. <body>
  10. <form action="finalpage.php" method="post">
  11. <?php
  12. //Redirect to orderpizza.php if orderid not set.
  13. if(!isset($_SESSION["orderid"])){
  14.     header("Location: orderpizza.php");
  15.     die();
  16. }
  17.  
  18. //Gather all data from the orderpizza.php page
  19. $productid=$_POST['prodid'];
  20. $orderid=$_SESSION["orderid"];
  21.  
  22. //Provide Database connection
  23. $dbhost = 'localhost:3306'; //hostname:port number
  24. $dbuser = 'root'; //username
  25. $dbpass = ''; //password
  26. $conn = mysql_connect($dbhost, $dbuser, $dbpass); //returns true or false
  27. if(! $conn )////display error message if connection fails
  28. {
  29.   die('Could not connect: ' . mysql_error());
  30. }
  31.  
  32. //Select records if orderID matches
  33. $sql = 'SELECT * FROM ORDER_PRODUCT WHERE ORDERID="'.$orderid.'"';
  34.  
  35. //select your database
  36. mysql_select_db('onlinepizzastore');
  37.  
  38. //run your query
  39. $retval = mysql_query( $sql, $conn );
  40.  
  41. //display error message if any
  42. if(! $retval )
  43. {
  44.   die('Could not get data: ' . mysql_error());
  45. }
  46.  
  47. //DELETEIF SAME ORDERID EXISTS
  48. if (!empty(mysql_fetch_array($retval, MYSQL_NUM))){
  49.         $sql = 'DELETE FROM ORDER_PRODUCT WHERE ORDERID="'.$orderid.'"';
  50.         $retval = mysql_query( $sql, $conn );
  51.         if(! $retval )
  52.         {
  53.           die('Could not get data: ' . mysql_error());
  54.         }
  55. }
  56.  
  57. //ADD PIZZA TO SHOPPING CART (ORDER_PRODUCT TABLE)
  58. $quantity=1; //ONLY 1 PIZZA CAN BE ORDERED AT A TIME
  59. $sql = 'INSERT INTO ORDER_PRODUCT VALUES ("'.$orderid.'","'.$productid.'",'.$quantity.')';
  60. $retval = mysql_query( $sql, $conn );
  61. if(! $retval )
  62. {
  63.   die('Could not enter data: ' . mysql_error());
  64. }
  65.  
  66. //DISPLAY TOPPINGS ON THE PAGE
  67. $sql = 'SELECT * FROM PRODUCTS WHERE PRODUCTTYPE=2';
  68. $retval = mysql_query( $sql, $conn );
  69. if(! $retval )
  70. {
  71.   die('Could not enter data: ' . mysql_error());
  72. }
  73.  
  74. //DISPLAY RECORDS IN TABLE FORMAT
  75. echo '<h2>Select Toppings here <br/></h2>';
  76. echo '<table>';
  77. while($row = mysql_fetch_array($retval, MYSQL_NUM)){
  78.     //checkbox for usersto check. Value assigned to be ID of the topping
  79.      echo '<tr> <td> <input type="checkbox" name="topping[]" value="'.$row[0].'"/>';
  80.      echo '<td>'.$row[1].'<br/>This Topping\'s price is $'.$row[2].'</td>';
  81.      echo ' <td> <img src="'.$row[4].'" name="prodid" width="150" height="150"/> </td>';  
  82.     //retrieve image names from database
  83. }
  84. echo '</table>';
  85.  
  86.  
  87.  
  88. echo '<br/><br/><a href="orderpizza.php"> Click here to change your pizza <a>';
  89.  
  90.  
  91. echo '<br/><br/><input type="Submit" Value="Click here to checkout"/>';
  92.  
  93. mysql_free_result($retval);
  94. mysql_close($conn);
  95.  
  96.  
  97. ?>
  98. </form>
  99. </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement