Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if( !isset( $_SESSION['fname'] ))
- {
- header("location: CR_login.php");
- }
- // Establish a connection to the database
- $con = mysqli_connect("localhost", "cairil_php", "phpsql");
- // Check if there were any issues connecting to the database
- if ( mysqli_connect_errno() != 0)
- {
- die("An error occurred trying to establish a connection: " .mysqli_connect_error());
- }
- // Select the database to work with.
- $db = mysqli_select_db ($con , "cairil_php");
- // Specify the query to run
- $sqlString = "SELECT * FROM Product";
- // Run the query using the connection established earlier and assign the results to a results object.
- $rs = mysqli_query ($con , $sqlString);
- ?>
- <html>
- <head>
- <title> CR_Products.php </title>
- </head>
- <center>
- <h1>Welcome <?php echo(($_SESSION['fname']) . " " . ($_SESSION['lname'])) ?></h1>
- <br />
- <h3>Product List</h3>
- <table border="2" align="center">
- <tbody>
- <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>
- <?php
- // While there is another record in the result object, fetch it
- while ($row = mysqli_fetch_array ($rs))
- {
- echo("<tr><td>");
- echo($row["ProductID"]);
- echo("</td><td>");
- echo($row["ProductName"]);
- echo("</td><td>");
- echo($row["UnitsInStock"]);
- echo("</td><td>");
- ?>
- <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>
- <?php
- }
- // Destroy the result object and release its memory
- mysqli_free_result($rs);
- // Close the connection
- mysqli_close($con);
- ?></td></tr>
- <tr bgcolor="#88ccaa">
- <td colspan="13" align="center"></td>
- </tr>
- </tbody>
- </table>
- <br /><br />
- <table>
- <tr>
- <td><a href=CR_products.php><img title"view products" src="/images/b-products.png" alt="View Product" /></a>
- <a href=CR_cart.php><img title"view cart" src="/images/b-shopping.png" alt="View Cart" /></a>
- <a href=CR_order.php><img title"view order" src="/images/b-orders.png" alt="View Orders"/></a></td></tr>
- <tr></tr> <tr></tr>
- <tr><td align="center"><a href=CR_welcome.php><img title="home" src="/images/home_button.png" alt="home" width="150" height="50"/></a> <a href=CR_logout.php><img title"logout" src="/images/exit_button.jpg" alt="Logout" /></a></td></tr>
- </table>
- </center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement