BLACKSITE
:
216.73.217.4
:
104.37.75.190 / alpenpass.ca
:
Linux server3.pointsplan.com 5.14.0-503.38.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 18 08:52:10 EDT 2025 x86_64
:
/
home2
/
apca
/
www
/
Upload File:
files >> //home2/apca/www/update_cart.php
<?php session_start(); include('includes/config.php'); // Include database connection // Ensure the user is logged in if (!isset($_SESSION['id'])) { die("User not logged in. Please log in to continue."); } // Ensure the request is POST if ($_SERVER['REQUEST_METHOD'] === 'POST') { $user_id = (int) $_SESSION['id']; // User ID from session $product_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; // Product ID from POST $quantity = isset($_POST['quantity']) ? (int) $_POST['quantity'] : 0; // Quantity from POST // Validate product_id and quantity if ($product_id <= 0 || $quantity <= 0) { die("Invalid product or quantity. POST data: " . print_r($_POST, true)); } try { // Check if the product exists in the cart for the user $stmt = $dbh->prepare("SELECT * FROM cart WHERE user_id = :user_id AND product_id = :product_id"); $stmt->execute([ ':user_id' => $user_id, ':product_id' => $product_id, ]); $cart_item = $stmt->fetch(PDO::FETCH_ASSOC); if ($cart_item) { // Update the quantity for the product in the cart $update_stmt = $dbh->prepare("UPDATE cart SET quantity = :quantity WHERE id = :id"); $update_stmt->execute([ ':quantity' => $quantity, ':id' => $cart_item['id'], ]); if ($update_stmt->rowCount() > 0) { $message= "Cart updated successfully."; } else { $message= "No changes made to the cart."; } // Redirect back to the cart header("Location: cart.php?updateMessage=$message"); exit; } else { $message= ("Product not found in the cart for the given user."); } } catch (PDOException $e) { die("Database error: " . $e->getMessage()); } } else { echo "Invalid request method."; }