Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>BuySpace!</title>
  5. <meta charset="UTF-8">
  6. <link rel="stylesheet" type="text/css" href="main.css">
  7.  
  8. <?php
  9. ini_set("display_errors", "on");
  10.  
  11.  
  12. // include "basketscript.php";
  13.  
  14.  
  15. // PHP login
  16. $username = 'c1626152';
  17. $password = 'aip7frashk';
  18. $host = 'csmysql.cs.cf.ac.uk';
  19. $dbname = 'c1626152';
  20.  
  21. // Connection PHP
  22. $connector = new mysqli($host,$username,$password,$dbname)
  23. or die("Unable to connect right now!");
  24. echo "Connection successful"; //
  25.  
  26. // ===Security script to stop potential MySQL exploit===
  27. // if(!isset ($_COOKIE['BuySpace.com'])) {
  28. // header('location: ./emptyPage.html');
  29. // exit;
  30. // }
  31.  
  32.  
  33. // This script only allows to view the basket items
  34. $sql = "SELECT * FROM MyGuests WHERE id='".$_SESSION['customer']."'";
  35. $sql2 = "SELECT * FROM products WHERE id='".$_SESSION['Basket']."'";
  36.  
  37. ?>
  38.  
  39.  
  40. </head>
  41.  
  42.  
  43. <body>
  44.  
  45.  
  46. <div class="mainbuttons-div" id="mainbuttons-div">
  47. <div class="logodiv">
  48. <a href="./home.php">
  49. <img class='logo' src="logo.jpg"/>
  50. </a>
  51. </div>
  52. </div>
  53. <!-- Menu created with help from https://www.w3schools.com/howto/howto_css_dropdown.asp -->
  54. <nav><div id = 'menu'> <!-- Menu divider -->
  55. <div class="dropdown-div"> <!-- shape button with this -->
  56. <button class="dropdown-btn"><img src="menu-btn.png" class="btn-img"/></button> <!-- Button itself -->
  57. <div class="dropdown-content">
  58. <a href="./home.php">Home</a>
  59. <a href="./emptyPage.html">About</a>
  60. <a href="./contact.html">Contact</a>
  61. </div>
  62. </div>
  63. <div class="basketdiv">
  64. <button onclick="location.href='./basket.php'" class="basket-btn" id="basket">
  65. <img src="shoppingCart.png" class="basket-img">
  66. </button>
  67. </div>
  68. </div>
  69. </nav>
  70.  
  71. <!-- Main page code -->
  72.  
  73. <div class = "basket-contents-div">
  74. <h2>Basket</h2>
  75.  
  76. <?php
  77.  
  78.  
  79.  
  80. print '<h2>Your Shopping Cart:</h2>';
  81. foreach ($_SESSION['basket'] as $key =>$quantity){
  82. print '<p class = "php_text">The Product ID: '.$_SESSION['id'].' </p>';
  83. }
  84. print '<p class = "php_text"> total cost: '$_SESSION['total'];
  85. print '<p class = "php_text"> Quantity: '.$_SESSION['quantity'].' </p>';
  86.  
  87. // if ($returned = mysql_query($sql, $connector)) {
  88.  
  89. // while ($row = mysql_fetch_array($returned)) {
  90. // print '<p class = "php_text"><b>Product Name: {'$row["name"]'}<br />
  91. // The Price: {'$row["price"]'}<br />
  92. // </p><hr />\n';
  93. // }
  94. // }
  95.  
  96. ?>
  97.  
  98. <form action="./pay.php">
  99. <input type="submit" value="confirm & Pay" class="pay-btn" /></div>
  100. </form>
  101.  
  102.  
  103.  
  104. </div>
  105.  
  106. ========================================================================================================================================
  107.  
  108. BASKETSCRIPT.PHP
  109.  
  110. <?php
  111.  
  112. ini_set("display_errors", "on");
  113.  
  114.  
  115.  
  116. // get customer ID to link to basket
  117.  
  118. $_SESSION['basket'] = array('id'=>$product['id'], 'quantity'=>$quantity);
  119.  
  120. $quantity = count($_SESSION['basket'])); //<====== Possible error on count() function
  121. print_r("Current basket: ",$_SESSION['basket']);
  122.  
  123. // $row = foreach($_SESSION['products'] AS $product){
  124. // print $product["name"];
  125. // }
  126.  
  127. // PHP login
  128. $username = 'c1626152';
  129. $password = 'aip7frashk';
  130. $host = 'csmysql.cs.cf.ac.uk';
  131. $dbname = 'c1626152';
  132.  
  133. //Basket vars
  134. session_start();
  135. // Start basket empty
  136. $quantity = 0;
  137.  
  138. $sql = "SELECT * FROM MyGuests";
  139. $result = $connector->query($sql);
  140. session_get_cookie_params();
  141. $id = $_COOKIE['customer'];
  142.  
  143. foreach($result as $customerInfo):
  144. if ($_COOKIE['customer'] == $customerInfo['customer']){
  145. $_SESSION['basket'] = array('id'=>$customer['id'], 'quantity'=>$quantity);
  146. }
  147.  
  148.  
  149.  
  150.  
  151. function addItem()
  152. array_push($_SESSION['basket'] , $product['id']]);
  153. foreach($basket['id'])
  154. if $basket['id'] == $_REQUEST['id']{
  155. $basket['quantity']++;
  156. break;
  157. }
  158.  
  159.  
  160. function deleteItem()
  161. $delete == $_SESSION['basket'];
  162.  
  163. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement