-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
125 lines (92 loc) · 4.2 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
117
118
119
120
121
122
123
124
125
<?php
include 'config.php';
session_start();
$user_id = $_SESSION['user_id'];
if (!isset($user_id)) {
header('location:login.php');
}
if (isset($_POST['update_cart'])) {
$cart_id = $_POST['cart_id'];
$cart_quantity = $_POST['cart_quantity'];
mysqli_query($conn, "UPDATE `cart` SET quantity = '$cart_quantity' WHERE id = '$cart_id'") or die('query failed');
$message[] = 'cart quantity updated!';
}
if (isset($_GET['delete'])) {
$delete_id = $_GET['delete'];
mysqli_query($conn, "DELETE FROM `cart` WHERE id = '$delete_id'") or die('query failed');
header('location:cart.php');
}
if (isset($_GET['delete_all'])) {
mysqli_query($conn, "DELETE FROM `cart` WHERE user_id = '$user_id'") or die('query failed');
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>cart</title>
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="./favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./favicon/favicon-16x16.png">
<link rel="manifest" href="./favicon/site.webmanifest">
<!-- 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/buynow.css">
</head>
<body>
<?php include 'header.php'; ?>
<div class="heading">
<h3>shopping cart</h3>
<p> <a href="home.php">home</a> / cart </p>
</div>
<section class="shopping-cart">
<h1 class="title">products added</h1>
<div class="box-container">
<?php
$grand_total = 0;
$select_cart = mysqli_query($conn, "SELECT * FROM `cart` WHERE user_id = '$user_id'") or die('query failed');
if (mysqli_num_rows($select_cart) > 0) {
while ($fetch_cart = mysqli_fetch_assoc($select_cart)) {
?>
<div class="box">
<a href="cart.php?delete=<?php echo $fetch_cart['id']; ?>" class="fas fa-times" onclick="return confirm('delete this from cart?');"></a>
<img src="uploaded_img/<?php echo $fetch_cart['image']; ?>" alt="">
<div class="name"><?php echo $fetch_cart['name']; ?></div>
<div class="name">🧭<?php echo $fetch_cart['libraryname']; ?></div>
<div class="price">₹<?php echo $fetch_cart['price']; ?>/-</div>
<form action="" method="post">
<input type="hidden" name="cart_id" value="<?php echo $fetch_cart['id']; ?>">
<input type="number" min="1" name="cart_quantity" value="<?php echo $fetch_cart['quantity']; ?>">
<input type="submit" name="update_cart" value="update" class="option-btn">
</form>
<div class="sub-total"> sub total : <span>₹<?php echo $sub_total = ($fetch_cart['quantity'] * $fetch_cart['price']); ?>/-</span> </div>
</div>
<?php
$grand_total += $sub_total;
}
} else {
echo '<p class="empty">your cart is empty</p>';
}
?>
</div>
<div style="margin-top: 2rem; text-align:center;">
<a href="cart.php?delete_all" class="delete-btn <?php echo ($grand_total > 1) ? '' : 'disabled'; ?>" onclick="return confirm('delete all from cart?');">delete all</a>
</div>
<div class="cart-total">
<p>grand total : <span>₹<?php echo $grand_total; ?>/-</span></p>
<div class="flex">
<a href="shop.php" class="option-btn">continue shopping</a>
<a href="checkout.php" class="btn <?php echo ($grand_total > 1) ? '' : 'disabled'; ?>">proceed to checkout</a>
</div>
</div>
</section>
<?php include 'footer.php'; ?>
<!-- custom js file link -->
<script src="js/script.js"></script>
</body>
</html>