���� JFIF fdasasfas213sdaf
Server IP : 147.79.69.218 / Your IP : 216.73.216.200 Web Server : LiteSpeed System : Linux in-mum-web669.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64 User : u479334040 ( 479334040) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/u479334040/domains/fossilstyle.com/public_html/ |
Upload File : |
<?php session_start(); include('includes/config.php'); // Add to Cart functionality if (isset($_POST['add_to_cart'])) { $product_id = filter_var($_GET['id'], FILTER_VALIDATE_INT); $quantity = filter_var($_POST['quantity'], FILTER_VALIDATE_INT); if ($product_id !== false && $quantity > 0) { // Get product details $sql = "SELECT * FROM products WHERE id = ?"; if ($stmt = $con->prepare($sql)) { $stmt->bind_param("i", $product_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $product = $result->fetch_assoc(); $productName = $product['productName']; $productPrice = $product['price']; // Prepare cart item $cart_item = [ 'id' => $product_id, 'name' => $productName, 'price' => $productPrice, 'quantity' => $quantity, 'total' => $productPrice * $quantity ]; // Check if the product is already in the cart if (isset($_SESSION['cart'][$product_id])) { $_SESSION['cart'][$product_id]['quantity'] += $quantity; $_SESSION['cart'][$product_id]['total'] = $_SESSION['cart'][$product_id]['price'] * $_SESSION['cart'][$product_id]['quantity']; } else { $_SESSION['cart'][$product_id] = $cart_item; } header('Location: cart.php'); // Redirect to the cart page exit(); } else { echo '<p>Product not found.</p>'; } } } else { echo '<p>Invalid quantity or product.</p>'; } } // Remove from Cart functionality if (isset($_GET['remove'])) { $product_id = filter_var($_GET['remove'], FILTER_VALIDATE_INT); if ($product_id !== false && isset($_SESSION['cart'][$product_id])) { unset($_SESSION['cart'][$product_id]); header('Location: cart.php'); exit(); } } // Clear the Cart if (isset($_GET['clear'])) { unset($_SESSION['cart']); header('Location: cart.php'); exit(); } // Calculate total cart value $total_price = 0; if (isset($_SESSION['cart']) && count($_SESSION['cart']) > 0) { foreach ($_SESSION['cart'] as $item) { $total_price += $item['total']; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Shopping Cart</title> <?php include 'assets.php'; ?> </head> <body> <?php include 'header.php'; ?> <section class="cart-section"> <div class="container-fluid-lg"> <div class="row"> <div class="col-12"> <h2>Your Cart</h2> <?php if (isset($_SESSION['cart']) && count($_SESSION['cart']) > 0): ?> <table class="table cart-table"> <thead> <tr> <th>Product</th> <th>Price</th> <th>Quantity</th> <th>Total</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($_SESSION['cart'] as $item): ?> <tr> <td><?php echo htmlspecialchars($item['name'], ENT_QUOTES, 'UTF-8'); ?></td> <td>₹<?php echo number_format($item['price'], 2); ?></td> <td><?php echo $item['quantity']; ?></td> <td>₹<?php echo number_format($item['total'], 2); ?></td> <td><a href="cart.php?remove=<?php echo $item['id']; ?>" class="btn btn-danger">Remove</a></td> </tr> <?php endforeach; ?> </tbody> </table> <div class="cart-total"> <h4>Total: ₹<?php echo number_format($total_price, 2); ?></h4> <a href="checkout.php" class="btn btn-primary">Proceed to Checkout</a> <a href="cart.php?clear=true" class="btn btn-warning">Clear Cart</a> </div> <?php else: ?> <p>Your cart is empty.</p> <?php endif; ?> </div> </div> </div> </section> <?php include 'footer.php'; ?> </body> </html>