Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <html>
- <head>
- <title> Choose toppings </title>
- <link rel="stylesheet" type="text/css" href="mystyle.css"/>
- </head>
- <body>
- <form action="finalpage.php" method="post">
- <?php
- //Redirect to orderpizza.php if orderid not set.
- if(!isset($_SESSION["orderid"])){
- header("Location: orderpizza.php");
- die();
- }
- //Gather all data from the orderpizza.php page
- $productid=$_POST['prodid'];
- $orderid=$_SESSION["orderid"];
- //Provide Database connection
- $dbhost = 'localhost:3306'; //hostname:port number
- $dbuser = 'root'; //username
- $dbpass = ''; //password
- $conn = mysql_connect($dbhost, $dbuser, $dbpass); //returns true or false
- if(! $conn )////display error message if connection fails
- {
- die('Could not connect: ' . mysql_error());
- }
- //Select records if orderID matches
- $sql = 'SELECT * FROM ORDER_PRODUCT WHERE ORDERID="'.$orderid.'"';
- //select your database
- mysql_select_db('onlinepizzastore');
- //run your query
- $retval = mysql_query( $sql, $conn );
- //display error message if any
- if(! $retval )
- {
- die('Could not get data: ' . mysql_error());
- }
- //DELETEIF SAME ORDERID EXISTS
- if (!empty(mysql_fetch_array($retval, MYSQL_NUM))){
- $sql = 'DELETE FROM ORDER_PRODUCT WHERE ORDERID="'.$orderid.'"';
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not get data: ' . mysql_error());
- }
- }
- //ADD PIZZA TO SHOPPING CART (ORDER_PRODUCT TABLE)
- $quantity=1; //ONLY 1 PIZZA CAN BE ORDERED AT A TIME
- $sql = 'INSERT INTO ORDER_PRODUCT VALUES ("'.$orderid.'","'.$productid.'",'.$quantity.')';
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not enter data: ' . mysql_error());
- }
- //DISPLAY TOPPINGS ON THE PAGE
- $sql = 'SELECT * FROM PRODUCTS WHERE PRODUCTTYPE=2';
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not enter data: ' . mysql_error());
- }
- //DISPLAY RECORDS IN TABLE FORMAT
- echo '<h2>Select Toppings here <br/></h2>';
- echo '<table>';
- while($row = mysql_fetch_array($retval, MYSQL_NUM)){
- //checkbox for usersto check. Value assigned to be ID of the topping
- echo '<tr> <td> <input type="checkbox" name="topping[]" value="'.$row[0].'"/>';
- echo '<td>'.$row[1].'<br/>This Topping\'s price is $'.$row[2].'</td>';
- echo ' <td> <img src="'.$row[4].'" name="prodid" width="150" height="150"/> </td>';
- //retrieve image names from database
- }
- echo '</table>';
- echo '<br/><br/><a href="orderpizza.php"> Click here to change your pizza <a>';
- echo '<br/><br/><input type="Submit" Value="Click here to checkout"/>';
- mysql_free_result($retval);
- mysql_close($conn);
- ?>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement