%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/www/website_6ca89795/ |
Upload File : |
<?php
// ✅ SESSION FIX
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
include('dbcon.php');
// ✅ Guest session
if (!isset($_SESSION['session_id'])) {
$_SESSION['session_id'] = session_create_id();
}
$user_id = isset($_SESSION['id']) ? $_SESSION['id'] : null;
$session_id = $_SESSION['session_id'];
// ✅ Fetch cart
if ($user_id) {
$stmt = $conn->prepare("
SELECT ci.id, ci.product_id, ci.quantity, p.price, p.title, p.image
FROM cart_items ci
JOIN areawecover p ON ci.product_id = p.id
WHERE ci.user_id = ?
ORDER BY ci.id DESC
");
$stmt->bind_param("i", $user_id);
} else {
$stmt = $conn->prepare("
SELECT ci.id, ci.product_id, ci.quantity, p.price, p.title, p.image
FROM cart_items ci
JOIN areawecover p ON ci.product_id = p.id
WHERE ci.session_id = ?
ORDER BY ci.id DESC
");
$stmt->bind_param("s", $session_id);
}
$stmt->execute();
$result = $stmt->get_result();
$cart_items = [];
$subtotal = 0;
while ($row = $result->fetch_assoc()) {
$row['quantity'] = (int)$row['quantity'];
$row['price'] = (float)$row['price'];
$row['total'] = $row['quantity'] * $row['price'];
$cart_items[] = $row;
$subtotal += $row['total'];
}
$stmt->close();
$conn->close();
include "header.php";
?>
<style>
.cart-box {
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.cart-table th {
background: #f8f9fa;
text-align: center;
}
.cart-table td {
text-align: center;
vertical-align: middle;
}
.cart-img {
width: 80px;
border-radius: 8px;
}
.qtyField {
display: flex;
justify-content: center;
gap: 5px;
}
.qtyBtn {
background: #222;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
text-decoration: none;
}
.qtyBtn:hover {
background: #139793;
}
.btn-cart {
background: linear-gradient(to right, #139793, #1edad4);
color: #fff;
padding: 8px 15px;
border-radius: 6px;
text-decoration: none;
}
</style>
<div class="container mt-4">
<div class="cart-box">
<?php if (empty($cart_items)) { ?>
<div class="alert alert-warning text-center">
Your cart is empty 😔 <br>
<a href="products.php" class="btn btn-primary mt-2">Shop Now</a>
</div>
<?php } else { ?>
<form action="update-cart.php" method="post">
<table class="table cart-table">
<thead>
<tr>
<th>Remove</th>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($cart_items as $item) { ?>
<tr>
<td>
<a href="remove-from-cart.php?id=<?php echo $item['id']; ?>" class="text-danger">✖</a>
</td>
<td style="text-align:left;">
<img src="admin/dataimg/<?php echo htmlspecialchars($item['image']); ?>" class="cart-img"><br>
<strong><?php echo htmlspecialchars($item['title']); ?></strong>
</td>
<td>KWD <?php echo number_format($item['price'], 2); ?></td>
<td>
<div class="qtyField">
<a href="update-cart.php?id=<?php echo $item['id']; ?>&action=minus" class="qtyBtn">-</a>
<input type="number"
name="quantity[<?php echo $item['id']; ?>]"
value="<?php echo $item['quantity']; ?>"
min="1"
style="width:60px;text-align:center;">
<a href="update-cart.php?id=<?php echo $item['id']; ?>&action=plus" class="qtyBtn">+</a>
</div>
</td>
<td>
<strong>USD <?php echo number_format($item['total'], 2); ?></strong>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="text-end mt-3">
<h5><strong>Subtotal: USD <?php echo number_format($subtotal, 2); ?></strong></h5>
<a href="products.php" class="btn-cart">Continue Shopping</a>
<a href="checkout.php" class="btn-cart">Checkout</a>
</div>
</form>
<?php } ?>
</div>
</div>
<?php include "footer.php"; ?>