-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
137 lines (111 loc) · 4.88 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
126
127
128
129
130
131
132
133
134
135
136
137
<?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['quantity'];
$update_query = mysqli_query($conn, "UPDATE `cart` SET quantity='$cart_quantity' WHERE id = '$cart_id'") or die("Query failed: " . mysqli_connect_error());
if ($update_query) {
$message[] = "Cart quantity updated successfully";
}
}
if (isset($_GET['delete_book'])) {
$cart_id = $_GET['delete_book'];
$delete_query = mysqli_query($conn, "DELETE FROM `cart` WHERE id = '$cart_id'") or die("Query failed: " . mysqli_connect_error());
if ($delete_query) {
header('Location: cart.php');
// $message[] = "Book deleted successfully";
}
}
if (isset($_GET['delete_all'])) {
$cart_id = $_GET['delete_book'];
$delete_query = mysqli_query($conn, "DELETE FROM `cart` WHERE user_id = '$user_id'") or die("Query failed: " . mysqli_connect_error());
if ($delete_query) {
header('Location: cart.php');
// $message[] = "Your Cart has been deleted successfully";
}
}
?>
<!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">
<meta name="description"
content="EGYBOOK Bookstore is one of the leading book seller in Egypt. Boasting more than 7,000 Arabic and foreign titles and aiming to provide the best book shopping experience." />
<title>EGYBOOK | Cart</title>
<!-- Tab Icon -->
<link rel="shortcut icon" href="img/logo.png" type="image/x-icon">
<!-- Fontawesome CDN Link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Custom CSS Style File -->
<link rel="stylesheet" href="css/styles.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">Books 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: " . mysqli_connect_error());
if (mysqli_num_rows($select_cart) > 0) {
while ($row = mysqli_fetch_assoc($select_cart)) {
?>
<div class="box">
<a href="cart.php?delete_book=<?php echo $row['id']; ?>" class="fas fa-times"
onclick="return confirm('Are You Sure Delete This Book From Cart?!');"></a>
<img src="uploaded_img/<?php echo $row['image']; ?>" alt="<?php echo $row['image']; ?>">
<div class="name"><?php echo $row['name']; ?></div>
<div class="price">$<?php echo $row['price']; ?>/-</div>
<form action="" method="post">
<input type="hidden" name="cart_id" value="<?php echo $row['id']; ?>">
<input type="number" min="1" name="quantity" value="<?php echo $row['quantity']; ?>">
<input type="submit" name="update_cart" value="Update" class="option-btn">
</form>
<div class="sub-total">sub-total:
<span>$<?php echo $sub_total = ($row['quantity'] * $row['price']); ?>/-</span>
</div>
</div>
<?php
$grand_total += $sub_total;
}
} else {
echo "<p class='empty'>No books added to cart</p>";
// echo "<style>
// .delete-all{
// display: none;
// }
// </style>";
}
?>
</div>
<div style="margin-top:2rem; text-align:center;">
<a href="cart.php?delete_all"
class="delete-btn delete-all <?php echo ($grand_total > 1) ? '' : 'disabled'; ?>"
onclick="return confirm('Are You Sure 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'; ?>
<script src="js/main.js"></script>
</body>
</html>