-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
116 lines (90 loc) · 3.51 KB
/
cart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
include 'config.php';
if(isset($_POST['update_update_btn'])){
$update_value = $_POST['update_quantity'];
$update_id = $_POST['update_quantity_id'];
$update_quantity_query = mysqli_query($conn, "UPDATE `cart` SET quantity = '$update_value' WHERE id = '$update_id'");
if($update_quantity_query){
header('location:cart.php');
};
};
if(isset($_GET['remove'])){
$remove_id = $_GET['remove'];
mysqli_query($conn, "DELETE FROM `cart` WHERE id = '$remove_id'");
header('location:cart.php');
};
if(isset($_GET['delete_all'])){
mysqli_query($conn, "DELETE FROM `cart`");
header('location:cart.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>shopping cart</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header.php'; ?>
<div class="container">
<section class="shopping-cart">
<h1 class="heading">giỏ hàng</h1>
<table>
<thead>
<th>ảnh</th>
<th>tên</th>
<th>giá</th>
<th>số lượng</th>
<th>tổng giá</th>
<th>lựa chọn</th>
</thead>
<tbody>
<?php
$select_cart = mysqli_query($conn, "SELECT * FROM `cart`");
$grand_total = 0;
if(mysqli_num_rows($select_cart) > 0){
while($fetch_cart = mysqli_fetch_assoc($select_cart)){
?>
<tr>
<td><img src="uploaded_img/<?php echo $fetch_cart['image']; ?>" height="100" alt=""></td>
<td><?php echo $fetch_cart['name']; ?></td>
<td><?php echo number_format($fetch_cart['price']); ?>VND</td>
<td>
<form action="" method="post">
<input type="hidden" name="update_quantity_id" value="<?php echo $fetch_cart['id']; ?>" >
<input type="number" name="update_quantity" min="1" value="<?php echo $fetch_cart['quantity']; ?>" >
<input type="submit" value="cập nhật" name="update_update_btn">
</form>
</td>
<td><?php $sub_total = ($fetch_cart['price'] * $fetch_cart['quantity']);
echo $sub_total_show = number_format($sub_total); ?>VND</td>
<td><a href="cart.php?remove=<?php echo $fetch_cart['id']; ?>" onclick="return confirm('Xóa sản phẩm khỏi giỏ?')" class="delete-btn"> <i class="fas fa-trash"></i> xóa</a></td>
</tr>
<?php
$grand_total += $sub_total;
};
};
?>
<tr class="table-bottom">
<td><a href="products.php" class="option-btn" style="margin-top: 0;">Tiếp tục mua sắm</a></td>
<td colspan="3">Tổng chi phí</td>
<td><?php echo number_format($grand_total); ?>VND</td>
<td><a href="cart.php?delete_all" onclick="return confirm('Bạn có chắc muốn xóa hết?');" class="delete-btn"> <i class="fas fa-trash"></i> Xóa hết </a></td>
</tr>
</tbody>
</table>
<div class="checkout-btn">
<a href="checkout.php" class="btn <?= ($grand_total > 1)?'':'disabled'; ?>">Tiến hành thanh toán</a>
</div>
</section>
</div>
<!-- custom js file link -->
<script src="js/script.js"></script>
</body>
</html>