Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title> Order Pizza Online </title>
- <link rel="stylesheet" type="text/css" href="mystyle.css"/>
- </head>
- <body>
- <form action="choosetoppings.php" method="post">
- <?php
- echo '<h1>Order Pizza Online</h1>';
- $dbhost = 'localhost:3306'; //hostname:port number
- $dbuser = 'root'; //username
- $dbpass = ''; //password
- $conn = mysql_connect($dbhost, $dbuser, $dbpass); //returns true or false
- //display error message if connection fails
- if(! $conn )
- {
- die('Could not connect: ' . mysql_error());
- }
- // SQL to fetch Pizza records
- $sql = 'SELECT * FROM PRODUCTS WHERE PRODUCTTYPE=1';
- //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());
- }
- //display records in table format
- echo '<h2>Click on the pizza image to order a pizza <br/></h2>';
- echo '<table border=1>'; //table tag constructs a table in HTML
- // mysql_fetch_array fetches an associative array by running the query and stores the result in $row
- //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
- //MYSQL_NUM returns the number of rows in the result. acts as a loop variable
- while($row = mysql_fetch_array($retval, MYSQL_NUM)){
- echo '<tr> <td>'.$row[1].'<br/>This Pizza\'s price is $'.$row[2].'</td>';
- echo ' <td> <input type="image" value="submit" src="'.$row[4].'" name="'.$row[0].'" width="350" height="350"/> </td>';
- echo ' <td> </td> ';
- echo ' <td> </td> </tr>';
- }
- echo ' </table>';
- mysql_free_result($retval);
- mysql_close($conn);
- ?>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement