%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : 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_93b53270/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_93b53270/addToCart.php
<?php
include "function.php";

if (isset($_POST['id']) && isset($_POST['quantity'])) {
    $productId = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
    $quantity = filter_input(INPUT_POST, 'quantity', FILTER_VALIDATE_INT);
    $total = filter_input(INPUT_POST, 'total', FILTER_VALIDATE_INT);
    $sevi_id = filter_input(INPUT_POST, 'sevi_id', FILTER_VALIDATE_INT);
    $parts = filter_input(INPUT_POST, 'parts', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
    $price = filter_input(INPUT_POST, 'price', FILTER_VALIDATE_INT);
    $oil_id = filter_input(INPUT_POST, 'oil_id', FILTER_VALIDATE_INT);

   // Validate quantity
    if (!$quantity || $quantity <= 0) {
        $response = array('status' => 'error', 'message' => 'Invalid quantity');
        echo json_encode($response);
        exit;
    }

    // Add the product to the cart
    if (!isset($_SESSION['cart'])) {
        $_SESSION['cart'] = array();
    }

    $productDetails = array(
        'price'=> $price,
        'parts'=> $parts,
        'sevi_id'=> $sevi_id,
        'total'=> $total,
        'oil_id'=> $oil_id,
        'quantity' => $quantity
    );

    if (!isset($_SESSION['cart'][$productId])) {
        $_SESSION['cart'][$productId] = $productDetails;
        $response = array('status' => 'success', 'message' => 'Product added successfully');
    } else {
    // If the product already exists in the cart, update its quantity
    $response = array('status' => 'error', 'message' => 'Product already exists in the cart');
    }

    echo json_encode($response);
} else {
    $response = array('status' => 'error', 'message' => 'Invalid request');
    echo json_encode($response);
}
?>

VaKeR 2022