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

$id = $_GET['id'];

$stmt = $pdo->prepare("SELECT quantity FROM cart WHERE id=?");
$stmt->execute([$id]);
$cart = $stmt->fetch();

if ($cart['quantity'] <= 1) {
    $pdo->prepare("DELETE FROM cart WHERE id=?")->execute([$id]);
} else {
    $pdo->prepare("UPDATE cart SET quantity = quantity - 1 WHERE id=?")->execute([$id]);
}

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