Advertisement
majse

cart.php

Jan 23rd, 2020
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. <!DOCTYPE>
  2. <?php
  3. session_start();
  4.  
  5. include("functions/functions.php");
  6.  
  7.  
  8. ?>
  9. <html>
  10. <head>
  11. <title>My Online Shop</title>
  12.  
  13.  
  14. <link rel="stylesheet" href="styles/style.css" media="all"/>
  15. </head>
  16.  
  17. <body>
  18.  
  19. <!--Main Container starts here-->
  20. <div class="main_wrapper">
  21.  
  22. <!--Header starts here-->
  23. <div class="header_wrapper">
  24.  
  25. <a href="index.php"><img id="logo" src="images/logo.gif" /></a>
  26. <img id="banner" src="images/ad_banner.gif" />
  27. </div>
  28. <!--Header ends here-->
  29.  
  30. <!--Navigation Bar starts here-->
  31. <div class="menubar">
  32.  
  33. <ul id="menu">
  34. <li><a href="index.php">Home</a></li>
  35. <li><a href="all_products.php">All Products</a></li>
  36. <li><a href="customer/my_account.php">My Account</a></li>
  37. <li><a href="#">Sign Up</a></li>
  38. <li><a href="cart.php">Shopping Cart</a></li>
  39. <li><a href="#">Contact Us</a></li>
  40.  
  41. </ul>
  42.  
  43. <div id="form">
  44. <form method="get" action="results.php" enctype="multipart/form-data">
  45.  
  46. <input type="text" name="user_query" placeholder="Search a Product"/>
  47. <input type="submit" name="search" value="Search" />
  48. </form>
  49.  
  50. </div>
  51.  
  52. </div>
  53. <!--Navigation Bar ends here-->
  54.  
  55. <!--Content wrapper starts-->
  56. <div class="content_wrapper">
  57.  
  58. <div id="sidebar">
  59.  
  60. <div id="sidebar_title">Categories</div>
  61.  
  62. <ul id="cats">
  63.  
  64.  
  65. <?php getCats(); ?>
  66.  
  67. </ul>
  68.  
  69. <div id="sidebar_title">Brands</div>
  70.  
  71. <ul id="cats">
  72.  
  73.  
  74. <?php getBrands(); ?>
  75.  
  76. </ul>
  77.  
  78. </div>
  79.  
  80.  
  81. <div id="content_area">
  82. <?php cart(); ?>
  83.  
  84.  
  85.  
  86. <div id="shopping_cart">
  87.  
  88. <span style="float:right; font-size:18px; padding:5px; line-height:40px;">
  89.  
  90. Welcome Guest! <b style="color:yellow">Shopping Cart -</b> Total Items <?php total_items();?> Total Price: <?php total_price(); ?> <a href="cart.php"style="color:yellow">Go to cart</a>
  91.  
  92.  
  93.  
  94. </span>
  95.  
  96.  
  97.  
  98. </div>
  99.  
  100.  
  101.  
  102. <div id="products_box">
  103.  
  104. <form action="" method="post" enctype="multipart/form-data">
  105.  
  106. <table align="center" width="700" bgcolor="skyblue">
  107.  
  108. <tr align="center">
  109. <th>Remove</th>
  110. <th>Product(S)</th>
  111. <th>Quantity</th>
  112. <th>Total Price</th>
  113. </tr>
  114.  
  115. <?php
  116. $total = 0;
  117.  
  118. global $con;
  119.  
  120. $ip = getIp();
  121.  
  122. $sel_price = "select * from cart where ip_add='$ip'";
  123.  
  124. $run_price = mysqli_query($con, $sel_price);
  125.  
  126. while($p_price=mysqli_fetch_array($run_price)) {
  127.  
  128. $pro_id = $p_price['p_id'];
  129.  
  130. $pro_price = "select * from products where product_id='$pro_id'";
  131.  
  132. $run_pro_price = mysqli_query($con,$pro_price);
  133.  
  134. while($pp_price = mysqli_fetch_array($run_pro_price)){
  135.  
  136. $product_price = array($pp_price['product_price']);
  137.  
  138. $product_title = $pp_price['product_title'];
  139.  
  140. $product_image = $pp_price['product_image'];
  141.  
  142. $single_price = $pp_price['product_price'];
  143.  
  144. $values = array_sum($product_price);
  145.  
  146. $total += $values;
  147.  
  148.  
  149. ?>
  150.  
  151. <tr align="center">
  152. <td><input type="checkbox" name="remove[]" value="<?php echo $pro_id;?>"/></td>
  153. <td><?php echo $product_title; ?><br>
  154. <img src="admin_area/product_images/<?php echo $product_image;?>" width="60" height="60"/>
  155. </td>
  156. <td><input type="text" size="4" name="qty" value="<?php echo $_SESSION['qty'];?>"/></td>
  157. <?php
  158. if(isset($_POST['update_cart'])){
  159.  
  160. $qty = $_POST['qty'];
  161.  
  162. $update_qty = "update cart set qty='$qty'";
  163.  
  164. $run_qty = mysqli_query($con, $update_qty);
  165.  
  166. $_SESSION['qty']=$qty;
  167.  
  168. $total = $total*$qty;
  169. }
  170.  
  171. ?>
  172. <td><?php echo "$" . $single_price; ?></td>
  173. </tr>
  174.  
  175.  
  176.  
  177. <?php } } ?>
  178.  
  179. <tr>
  180. <td colspan="4" align="right"><b>Sub Total:</b></td>
  181. <td><?php echo "$" . $total;?></td>
  182. </tr>
  183. <tr align="center">
  184. <td colspan="2"><input type="submit" name="update_cart" value="Update Cart"/></td>
  185. <td><input type="submit" name="continue" value="Continue Shopping" /></td>
  186. <td><button><a href="checkout.php" style="text-decoration:none; color:black;">Checkout</a></button></td>
  187. </tr>
  188.  
  189. </table>
  190.  
  191.  
  192. </form>
  193.  
  194. <?php
  195.  
  196. function updatecart(){
  197.  
  198. global $con;
  199.  
  200. $ip = getIp();
  201.  
  202. if (isset($_POST['update_cart'])) {
  203.  
  204. foreach($_POST['remove'] as $remove_id){
  205.  
  206. $delete_product = "delete from cart where p_id='$remove_id' AND ip_add='$ip'";
  207.  
  208.  
  209. $run_delete = mysqli_query($con, $delete_product);
  210.  
  211. if($run_delete){
  212.  
  213. echo "<script>window.open('cart.php','_self')</script>";
  214. }
  215.  
  216. echo @$up_cart = updatecart();
  217. }
  218.  
  219.  
  220. }
  221.  
  222. if (isset($_POST['continue'])){
  223.  
  224. echo "<script>window.open('cart','_self')</script>";
  225. }
  226.  
  227. }
  228.  
  229. ?>
  230.  
  231.  
  232. </div>
  233.  
  234. </div>
  235.  
  236. </div>
  237. <!--Content wrapper ends-->
  238.  
  239. <div id="footer">
  240.  
  241. <h2 style="text-align:center; padding-top:30px;">&copy; 2019 by www.majse.com</h2>
  242.  
  243. </div>
  244.  
  245.  
  246. </div>
  247. <!--Main Container ends here-->
  248.  
  249.  
  250.  
  251. </body>
  252. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement