Advertisement
Guest User

Untitled

a guest
May 9th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Order Pizza Online </title>
  4. <link rel="stylesheet" type="text/css" href="mystyle.css"/>
  5. </head>
  6. <body>
  7. <form action="choosetoppings.php" method="post">
  8. <?php
  9. echo '<h1>Order Pizza Online</h1>';
  10.  
  11. $dbhost = 'localhost:3306'; //hostname:port number
  12. $dbuser = 'root'; //username
  13. $dbpass = ''; //password
  14. $conn = mysql_connect($dbhost, $dbuser, $dbpass); //returns true or false
  15.  
  16. //display error message if connection fails
  17. if(! $conn )
  18. {
  19. die('Could not connect: ' . mysql_error());
  20. }
  21.  
  22. // SQL to fetch Pizza records
  23. $sql = 'SELECT * FROM PRODUCTS WHERE PRODUCTTYPE=1';
  24.  
  25. //select your database
  26. mysql_select_db('onlinepizzastore');
  27.  
  28. //run your query
  29. $retval = mysql_query( $sql, $conn );
  30.  
  31. //display error message if any
  32. if(! $retval )
  33. {
  34. die('Could not get data: ' . mysql_error());
  35. }
  36.  
  37. //display records in table format
  38. echo '<h2>Click on the pizza image to order a pizza <br/></h2>';
  39. echo '<table border=1>'; //table tag constructs a table in HTML
  40.  
  41. // mysql_fetch_array fetches an associative array by running the query and stores the result in $row
  42. //Since we have SELECT * FROM PRODUCTS and there are 5 columns in PRODUCTS table, row[0] gives you the first column, row[1] the second and row[4] the last column
  43. //MYSQL_NUM returns the number of rows in the result. acts as a loop variable
  44. while($row = mysql_fetch_array($retval, MYSQL_NUM)){
  45.  
  46. echo '<tr> <td>'.$row[1].'<br/>This Pizza\'s price is $'.$row[2].'</td>';
  47. echo ' <td> <input type="image" value="submit" src="'.$row[4].'" name="'.$row[0].'" width="350" height="350"/> </td>';
  48. echo ' <td> </td> ';
  49. echo ' <td> </td> </tr>';
  50. }
  51. echo ' </table>';
  52.  
  53. mysql_free_result($retval);
  54. mysql_close($conn);
  55. ?>
  56. </form>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement