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
/
public_html
/
Upload File:
files >> //home2/apca/public_html/add_to_cart.php
<?php session_start(); include('includes/config.php'); // Include database configuration if ($_SERVER['REQUEST_METHOD'] == 'POST') { $user_id = $_SESSION['id'] ?? null; // Ensure user is logged in if (!$user_id) { die("You must be logged in to add items to the cart."); } // Get product details from the form submission $product_id = $_POST['productID'] ?? null; $product_name = $_POST['ProductName'] ?? ''; $quantity = $_POST['quantity'] ?? 1; $price = $_POST['price'] ?? 0.0; $model_number = $_POST['Model_Number'] ?? ''; $category = $_POST['Category'] ?? ''; $size = $_POST['Size'] ?? ''; $color = $_POST['Color'] ?? ''; $weight = $_POST['Weight'] ?? ''; $upc = $_POST['UPC'] ?? ''; $ProductsGSTRate = $_POST['ProductsGSTRate'] ?? ''; $ProductsPSTRate = $_POST['ProductsPSTRate'] ?? ''; $date_added = date('Y-m-d H:i:s'); // Current date and time // Validate required fields if (!$product_id || !$product_name || $price <= 0) { die("Invalid product data. Please try again."); } try { // Check if the product already exists in the cart $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 quantity if the item already exists $new_quantity = $cart_item['quantity'] + $quantity; $update_stmt = $dbh->prepare("UPDATE cart SET quantity = :quantity, date_added = :date_added WHERE id = :id"); $update_stmt->execute([ ':quantity' => $new_quantity, ':date_added' => $date_added, ':id' => $cart_item['id'], ]); } else { // Insert new item into the cart $insert_stmt = $dbh->prepare("INSERT INTO cart (user_id, product_id, product_name, quantity, price, model_number, category, size, color, weight, upc, date_added) VALUES (:user_id, :product_id, :product_name, :quantity, :price, :model_number, :category, :size, :color, :weight, :upc, :date_added)"); $insert_stmt->execute([ ':user_id' => $user_id, ':product_id' => $product_id, ':product_name' => $product_name, ':quantity' => $quantity, ':price' => $price, ':model_number' => $model_number, ':category' => $category, ':size' => $size, ':color' => $color, ':weight' => $weight, ':upc' => $upc, ':ProductsGSTRate' => $ProductsGSTRate, ':ProductsPSTRate' => $ProductsPSTRate, ':date_added' => $date_added, ]); } header('Location: cart.php'); exit; } catch (PDOException $e) { die("Error adding to cart: " . $e->getMessage()); } } else { echo "Invalid request."; } ?>