Advertisement
Guest User

tunglv

a guest
Nov 26th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. <?php
  2. include ("connect/connect_db.php");
  3. if(isset($_POST['submit']))
  4. {
  5. foreach($_POST['qty'] as $key=>$value){
  6. if( ($value == 0) and (is_numeric($value))){
  7. unset ($_SESSION['cart'][$key]);
  8. }
  9. else if(($value > 0) and (is_numeric($value))){
  10. $_SESSION['cart'][$key]=$value;
  11. }
  12. }
  13. header("location:cart.php");
  14. }
  15. ?>
  16.  
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title><?php echo (isset($title)?$title:'Giỏ hàng'); ?></title>
  22. <link href="css/index.css" rel="stylesheet" type="text/css"/>
  23. </head>
  24. <body>
  25.  
  26. <header>
  27. <p>Language: <a href="#">Vietnamese</a></p>
  28. <div id="logo">
  29. <img src="img/logo-htc.png"/>
  30. <h1>IN VIET NAM</h1>
  31. </div>
  32.  
  33. </header>
  34.  
  35. <section id="menu-top">
  36. <a id="catergories" href="index.php">
  37. <img src="img/home-icon.png"/>
  38. <p>Trang chủ</p>
  39. </a>
  40. <p class="supports">CSKH: 01662623935 - 0979666999</p>
  41. <div id="search-bar">
  42. <input type="text" name="search" placeholder="Nhập từ khóa" id="search"/>
  43. <input type="submit" id="submit" value=""/>
  44. </div>
  45.  
  46.  
  47. <ul id="main_menu">
  48. <li <?php echo (!isset($_GET['cate'])?:NUll); ?> ><a href="index.php">HTC One</a></li>
  49. <li <?php echo ((isset($_GET['cate']) && $_GET['cate']=='htc')?"style='text-decoration:underline'":NUll); ?>><a href="index.php?action=product&cate=htc">HTC Desire</a></li>
  50. <li <?php echo ((isset($_GET['cate']) && $_GET['cate']=='thongminh')?"style='text-decoration:underline'":NUll); ?>><a href="index.php?action=product&cate=thongminh">Điện thoại thông minh khác</a></li>
  51. <li <?php echo ((isset($_GET['cate']) && $_GET['cate']=='phukien')?"style='text-decoration:underline'":NUll); ?>><a href="index.php?action=product&cate=phukien">Phụ kiện</a></li>
  52. </ul>
  53.  
  54.  
  55. </section>
  56.  
  57. <section id='cart_content'>
  58. <h1 id='shopcart'>GIỎ HÀNG CỦA BẠN</h1>
  59. <?php
  60. $total="";
  61. $ok=1;
  62. if(isset($_SESSION['cart'])){
  63. foreach($_SESSION['cart'] as $k => $v){
  64. if(isset($k)){
  65. $ok=2;
  66. }
  67. }
  68. }
  69.  
  70. if($ok == 2){
  71. echo "<form action='cart.php' method='post'>";
  72. foreach($_SESSION['cart'] as $key=>$value){
  73. if($key!='total'){
  74. $item[]=$key;
  75. }
  76.  
  77. }
  78.  
  79. $str=implode(",",$item);
  80. $sql="select * from products where id_product in ($str)";
  81. $query=mysql_query($sql);
  82.  
  83. //in ra bảng
  84. echo "<table>";
  85. echo "<thead>";
  86. echo "<tr>";
  87. echo "<th>Tên sản phẩm</th>";
  88. echo "<th>Đơn Giá</th>";
  89. echo "<th>Số lượng</th>";
  90. echo "<th>Thành tiền</th>";
  91. echo "<th>Thao tác</th>";
  92. echo "</tr>";
  93. echo "</thead>";
  94. echo "<tbody>";
  95.  
  96. while($row=mysql_fetch_array($query)){
  97.  
  98. $total += $_SESSION['cart'][$row['id_product']]*$row['cost'];
  99. $_SESSION['cart']['total']= $total ;
  100. echo "<tr>";
  101. echo "<td>$row[name]</td>";
  102. echo "<td>".$row['cost']."</td><br />";
  103. echo "<td><input type='number' min='1' max='100' size='2' name='qty[".$row['id_product']."]' size='5' value='".$_SESSION['cart'][$row['id_product']]."'- ></td>";
  104. echo "<td>". number_format($_SESSION['cart'][$row['id_product']]*$row['cost'],6) ." VND</td>";
  105. echo "<td><a id='del' href='delcart.php?productid=$row[id_product]'>Xóa</a> <input id='update' type='submit' name='submit' value='Cập nhật'></td>";
  106. echo "</tr>";
  107. echo "</tbody>";
  108.  
  109. }
  110. echo "<thead>";
  111. echo "<tr>";
  112. echo "<th>Tổng cộng</th>";
  113. echo "<th></th>";
  114. echo "<th>" .count($item). " sản phẩm</th>";
  115. echo "<th> <font color='red' size='3'>".number_format($total,6)." VND</font></th>";
  116. echo "<th><a id='order' href='order.php'>ĐẶT HÀNG</a></th>";
  117. echo "</tr>";
  118. echo "</thead>";
  119.  
  120. echo "</table>";
  121. echo "<div class='pro' align='center'>";
  122. echo "<b><a href='index.php'>Tiếp tục mua sắm</a> - <a href='delcart.php?productid=0'>Xóa bỏ giỏ hàng</a></b>";
  123. echo "</div>";
  124.  
  125. }
  126. else
  127. {
  128. echo "<div class='pro'>";
  129. echo "<p align='center'>Bạn không có món hàng nào trong giỏ<br /><a href='index.php'>Mua hàng</a></p>";
  130. echo "</div>";
  131. }
  132.  
  133. ?>
  134.  
  135. </section>
  136.  
  137.  
  138. <footer>
  139. <h4>LIÊN HỆ VỚI CHÚNG TÔI: </h4>
  140. <p><a href="#">Gọi điện</a> <a href="#">Email Hỗ trợ</a> <a href="#">Lên lịch hẹn</a></p>
  141. <img src="img/logo-htc2.png" width='100'/>
  142. <p id="bq">Bản quyền 2014 HTC Corporation. Mọi quyền được bảo lưu.</p>
  143. </footer>
  144. </body>
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement