<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $productId = isset($_POST['id']) ? intval($_POST['id']) : 0;
    $quantity = isset($_POST['qty']) ? max(1, intval($_POST['qty'])) : 1;

    if ($productId > 0 && isset($_SESSION['cart'][$productId])) {
        $_SESSION['cart'][$productId]['qty'] = $quantity;
    }
}

header("Location: cart.php");
exit;
?>
