<?php

include '../admin/config/db.php'; // مسیر درست به فایل دیتابیس



$id = $_GET['id'];

// بقیه کد محصول...

$user_id = 1; // فعلاً تستی
$product_id = $_POST['product_id'];

$check = $pdo->prepare("SELECT * FROM cart WHERE user_id=? AND product_id=?");
$check->execute([$user_id, $product_id]);

if ($check->rowCount() > 0) {
    $pdo->prepare("UPDATE cart SET quantity = quantity + 1 WHERE user_id=? AND product_id=?")
        ->execute([$user_id, $product_id]);
} else {
    $pdo->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, 1)")
        ->execute([$user_id, $product_id]);
}

header("Location: cart.php");
exit;
?>