Advertisement
giraffeinatutu

Products 8.22 9p

Aug 22nd, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php  
  2.     session_start();
  3.     if( !isset( $_SESSION['fname'] ))
  4.     {
  5.     header("location: CR_login.php");
  6.     }
  7.  
  8.     // Establish a connection to the database
  9.     $con =  mysqli_connect("localhost", "cairil_php", "phpsql");
  10.  
  11.     // Check if there were any issues connecting to the database
  12.     if ( mysqli_connect_errno() != 0)
  13.     {
  14.        die("An error occurred trying to establish a connection: " .mysqli_connect_error());
  15.     }
  16.    
  17.     // Select the  database to work with.
  18.     $db  =  mysqli_select_db ($con , "cairil_php");
  19.  
  20.     // Specify the query to run
  21.     $sqlString = "SELECT * FROM  Product";
  22.    
  23.     // Run the query using the connection established earlier and assign the results to a results object.
  24.     $rs = mysqli_query ($con  , $sqlString);
  25.    
  26.  
  27.  
  28.     ?>
  29.    
  30. <html>
  31.     <head>
  32.         <title> CR_Products.php </title>
  33.     </head>
  34.  
  35. <center>
  36. <h1>Welcome <?php echo(($_SESSION['fname']) . " " . ($_SESSION['lname'])) ?></h1>
  37. <br />
  38. <h3>Product List</h3>
  39. <table border="2" align="center">
  40. <tbody>
  41. <tr bgcolor="#88ccaa"><th align="center">Product ID</th><th align="center">Product Name</th><th align="center">Units In Stock</th><th align="center">Add To Cart</th></tr>
  42. <?php
  43.             // While there is another record in the result object, fetch it
  44.             while ($row = mysqli_fetch_array ($rs))
  45.             {
  46.                 echo("<tr><td>");
  47.                 echo($row["ProductID"]);
  48.                 echo("</td><td>");
  49.                 echo($row["ProductName"]);
  50.                 echo("</td><td>");
  51.                 echo($row["UnitsInStock"]);
  52.                 echo("</td><td>");
  53.                 ?>
  54.                 <a href=CR_cart.php?action=add&id=$row["ProductID"])><img title="Add to Cart" src="/images/add.png" alt="Add to Cart" width="100" height="30" /></a>
  55.         <?php  
  56.             }          
  57.             // Destroy the result object and release its memory
  58.             mysqli_free_result($rs);
  59.                
  60.             // Close the connection
  61.             mysqli_close($con);    
  62.         ?></td></tr>
  63. <tr bgcolor="#88ccaa">
  64. <td colspan="13" align="center"></td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. <br /><br />
  69. <table>
  70. <tr>
  71. <td><a href=CR_products.php><img title"view products" src="/images/b-products.png" alt="View Product" /></a>
  72.     <a href=CR_cart.php><img title"view cart" src="/images/b-shopping.png" alt="View Cart" /></a>
  73.     <a href=CR_order.php><img title"view order" src="/images/b-orders.png" alt="View Orders"/></a></td></tr>
  74.     <tr></tr>    <tr></tr>
  75.     <tr><td align="center"><a href=CR_welcome.php><img title="home" src="/images/home_button.png" alt="home" width="150" height="50"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=CR_logout.php><img title"logout" src="/images/exit_button.jpg" alt="Logout" /></a></td></tr>
  76. </table>    
  77. </center>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement