Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <Head>
  2. <script
  3. src="https://code.jquery.com/jquery-3.3.1.js"
  4. integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  5. crossorigin="anonymous"></script>
  6.  
  7. <link href="style.css" type="text/css" rel="stylesheet" />
  8. <style>
  9. #product{
  10. width:500px;
  11. text-align: center;
  12. }
  13.  
  14.  
  15. #quantity{
  16. width: 50px;
  17. text-align: center;
  18. }
  19.  
  20. #price{
  21. text-align: right;
  22. }
  23.  
  24. input:focus {
  25. outline:none;
  26. }
  27.  
  28. input{
  29. width: 100%;
  30. }
  31.  
  32. input[type="text"]
  33. {
  34. font-size:1em;
  35. text-align: center;
  36. }
  37.  
  38. td
  39. {
  40. font-size: 1em;
  41. font-family: arial;
  42. white-space: nowrap; /** added **/
  43. }
  44.  
  45. th {
  46. font-size: 1.2em;
  47. font-family: arial;
  48. }
  49.  
  50. table{
  51. table-layout: auto;
  52. border-spacing: 10px 0;
  53. }
  54. </style>
  55. </head>
  56.  
  57. <div id="shopping-cart">
  58. <div class="txt-heading">
  59. <div class="txt-heading-label">Shopping Cart</div>
  60. <a id="btnEmpty"><img src="empty-cart.png" id= "emptycart" alt="empty-cart" title="Empty Cart" /></a>
  61. </div>
  62. <?php
  63. session_start();
  64.  
  65. $servername = "localhost";
  66. $username = "root";
  67. $password = "";
  68. $dbname = "secure_login";
  69. $member_id = $_SESSION['login_user'];
  70.  
  71. // Create connection
  72. $conn = new mysqli($servername, $username, $password, $dbname);
  73. // Check connection
  74. if ($conn->connect_error) {
  75. die("Connection failed: " . $conn->connect_error);
  76. }
  77. ?>
  78.  
  79. <?php
  80. $query = "select * from tbl_cart WHERE member_id= '$member_id'";
  81. $result = mysqli_query($conn,$query);
  82. if (!$result) {
  83. printf("Error: %sn", mysqli_error($conn));
  84. exit();
  85. }
  86.  
  87. echo "<table class='anyClass'>";
  88. echo "<tr>
  89. <th>Product</th>
  90. <th>Price</th>
  91. <th>Quantity</th>
  92. <th>Remove</th>
  93. <th>Add</th>
  94.  
  95. </tr>";
  96. while($row = $result->fetch_assoc()) {
  97. echo "<tr>
  98.  
  99. <td id='product'>".$row['product_id']."</td>
  100. <td id= 'price'>".'$'.$row['price']."</td>
  101. <td id= 'quantity'>". "<input style='border:none' type = 'text' onchange='edit()' 'class = 'product-item' class= 'change' value= $row[quantity] name= $row[id] data-id= $row[id] >" . "</td>
  102. <td><span class='delete' data-id= $row[id] >Delete</span></td>
  103. </tr>";
  104. }
  105. echo "</table>";
  106. ?>
  107.  
  108.  
  109. <script>
  110. $(document).ready(function(){
  111.  
  112. // Delete
  113. $('.delete').click(function(){
  114. var el = this;
  115. var id = $(el).data('id');
  116.  
  117. // AJAX Request
  118. $.ajax({
  119. url: 'remove.php',
  120. type: 'POST',
  121. data: { id: id},
  122. success: function(response){
  123.  
  124. // Removing row from HTML Table
  125. $(el).closest('tr').css('background','tomato');
  126. $(el).closest('tr').fadeOut(800, function(){
  127. $(this).remove();
  128. });
  129.  
  130. }
  131. });
  132. });
  133. });
  134. </script>
  135. <script>
  136.  
  137. $( ".change" ).change(function() {
  138. var el = this;
  139. var id = $(el).data('id');
  140.  
  141. // AJAX Request
  142. $.ajax({
  143. url: 'update.php',
  144. type: 'POST',
  145. data: { id: id quantity: value},
  146. success: function(response){
  147. }
  148. });
  149. });
  150. });
  151. </script>
  152.  
  153. <?php
  154. session_start();
  155.  
  156. $servername = "localhost";
  157. $username = "root";
  158. $password = "";
  159. $dbname = "secure_login";
  160. $member_id = $_SESSION['login_user'];
  161.  
  162. // Create connection
  163. $conn = new mysqli($servername, $username, $password, $dbname);
  164. // Check connection
  165. if ($conn->connect_error) {
  166. die("Connection failed: " . $conn->connect_error);
  167. }
  168. $quantity = $_POST['quantity'];
  169. $id = $_POST['id'];
  170.  
  171. $query = "UPDATE tbl_cart SET quantity= $quantity WHERE id= $id";
  172. mysqli_query($conn,$query);
  173. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement