Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2. // Session code found at https://code.tutsplus.com/tutorials/build-a-shopping-cart-with-php-and-mysql--net-5144
  3. session_start();
  4. ?>
  5. <!DOCTYPE HTML>
  6. <html lang="en">
  7.  
  8. <head>
  9. <meta charset="utf-8">
  10.  
  11. <link rel="stylesheet" type="text/css" href="stylesheet.css">
  12.  
  13. <title>Ross' Mug Shop</title>
  14.  
  15. </head>
  16. <body>
  17. <nav>
  18. <h1>
  19. Ross' Mug Shop
  20. </h1>
  21. <ul>
  22. <li><a href="index.php">View Home Page</a></li>
  23. </ul>
  24. </nav>
  25.  
  26. </body>
  27.  
  28. <code>
  29. <?php
  30. $server="csmysql.cs.cf.ac.uk";
  31. $user="c1615528";
  32. $password="";
  33. $database="c1615528";
  34. $mugTable="SELECT * FROM Mugs";
  35. $connect = new mysqli($server, $user, $password, $database);
  36. $result= $connect->query($mugTable);
  37.  
  38. if(isset($_GET['action']) && $_GET['action'] == "add") {
  39. $mugName = $_GET['id'];
  40. if (isset($_SESSION['cart'][$mugName])) {
  41. $_SESSION['cart'][$mugName]['quantity'] ++;
  42. }
  43. else {
  44. $selectMug="SELECT * FROM Mugs WHERE mugName={$mugName}";
  45. $query_s=$connect->query($selectMug);
  46. $row_s=$query_s->fetch_array();
  47. $_SESSION['cart'][$row_s['mugName']]=array(
  48. "quantity" => 1,
  49. "price" => $row_s['mugPrice']
  50. );
  51. }
  52. }
  53.  
  54. $mugName2 = $_GET['id'];
  55. $getMug = "SELECT * FROM Mugs WHERE mugName={$mugName2}";
  56. $query=$connect->query($getMug);
  57. $mug=$query->fetch_array();
  58. ?>
  59. </code>
  60.  
  61. <body>
  62. <?php
  63. $mugName3 = $mug['mugName'];
  64. $mugPrice = $mug['mugPrice'];
  65. $mugImage = $mug['mugImage'];
  66. $mugDesc = $mug['mugDescription'];
  67. ?>
  68. <div class="productImage"><img src="<?php echo $mugImage ?>" width="100" height="100"></div>
  69. <div class="productName"><?php echo $mugName3 ?></div>
  70. <div class="productPrice">£<?php echo $mugPrice ?></div>
  71. <div class="productDesc"><?php echo $mugDesc ?></div>
  72. <div><a href="index.php?page=index&action=add&id=<?php echo $mugName3 ?>">Add to cart</a></div>
  73.  
  74. <?php
  75. // Close the connection
  76. mysqli_close($con);
  77. ?>
  78.  
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement