Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include ("connect/connect_db.php");
- if(isset($_POST['submit']))
- {
- foreach($_POST['qty'] as $key=>$value){
- if( ($value == 0) and (is_numeric($value))){
- unset ($_SESSION['cart'][$key]);
- }
- else if(($value > 0) and (is_numeric($value))){
- $_SESSION['cart'][$key]=$value;
- }
- }
- header("location:cart.php");
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title><?php echo (isset($title)?$title:'Giỏ hàng'); ?></title>
- <link href="css/index.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <header>
- <p>Language: <a href="#">Vietnamese</a></p>
- <div id="logo">
- <img src="img/logo-htc.png"/>
- <h1>IN VIET NAM</h1>
- </div>
- </header>
- <section id="menu-top">
- <a id="catergories" href="index.php">
- <img src="img/home-icon.png"/>
- <p>Trang chủ</p>
- </a>
- <p class="supports">CSKH: 01662623935 - 0979666999</p>
- <div id="search-bar">
- <input type="text" name="search" placeholder="Nhập từ khóa" id="search"/>
- <input type="submit" id="submit" value=""/>
- </div>
- <ul id="main_menu">
- <li <?php echo (!isset($_GET['cate'])?:NUll); ?> ><a href="index.php">HTC One</a></li>
- <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>
- <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>
- <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>
- </ul>
- </section>
- <section id='cart_content'>
- <h1 id='shopcart'>GIỎ HÀNG CỦA BẠN</h1>
- <?php
- $total="";
- $ok=1;
- if(isset($_SESSION['cart'])){
- foreach($_SESSION['cart'] as $k => $v){
- if(isset($k)){
- $ok=2;
- }
- }
- }
- if($ok == 2){
- echo "<form action='cart.php' method='post'>";
- foreach($_SESSION['cart'] as $key=>$value){
- if($key!='total'){
- $item[]=$key;
- }
- }
- $str=implode(",",$item);
- $sql="select * from products where id_product in ($str)";
- $query=mysql_query($sql);
- //in ra bảng
- echo "<table>";
- echo "<thead>";
- echo "<tr>";
- echo "<th>Tên sản phẩm</th>";
- echo "<th>Đơn Giá</th>";
- echo "<th>Số lượng</th>";
- echo "<th>Thành tiền</th>";
- echo "<th>Thao tác</th>";
- echo "</tr>";
- echo "</thead>";
- echo "<tbody>";
- while($row=mysql_fetch_array($query)){
- $total += $_SESSION['cart'][$row['id_product']]*$row['cost'];
- $_SESSION['cart']['total']= $total ;
- echo "<tr>";
- echo "<td>$row[name]</td>";
- echo "<td>".$row['cost']."</td><br />";
- 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>";
- echo "<td>". number_format($_SESSION['cart'][$row['id_product']]*$row['cost'],6) ." VND</td>";
- 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>";
- echo "</tr>";
- echo "</tbody>";
- }
- echo "<thead>";
- echo "<tr>";
- echo "<th>Tổng cộng</th>";
- echo "<th></th>";
- echo "<th>" .count($item). " sản phẩm</th>";
- echo "<th> <font color='red' size='3'>".number_format($total,6)." VND</font></th>";
- echo "<th><a id='order' href='order.php'>ĐẶT HÀNG</a></th>";
- echo "</tr>";
- echo "</thead>";
- echo "</table>";
- echo "<div class='pro' align='center'>";
- 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>";
- echo "</div>";
- }
- else
- {
- echo "<div class='pro'>";
- 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>";
- echo "</div>";
- }
- ?>
- </section>
- <footer>
- <h4>LIÊN HỆ VỚI CHÚNG TÔI: </h4>
- <p><a href="#">Gọi điện</a> <a href="#">Email Hỗ trợ</a> <a href="#">Lên lịch hẹn</a></p>
- <img src="img/logo-htc2.png" width='100'/>
- <p id="bq">Bản quyền 2014 HTC Corporation. Mọi quyền được bảo lưu.</p>
- </footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement