// 1. Input validation $product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT); $quantity = filter_input(INPUT_POST, 'num', FILTER_VALIDATE_INT, [ 'options' => ['min_range' => 1, 'max_range' => 99] ]);
if (isset($_SESSION['cart'][$product_id])) $_SESSION['cart'][$product_id] += $quantity; else $_SESSION['cart'][$product_id] = $quantity; add-cart.php num
The num parameter (often named qty , quantity , or count ) tells the backend how many units of a product to place into the session array. $quantity = filter_input(INPUT_POST
// Handle remove/update actions if ($_SERVER['REQUEST_METHOD'] == 'POST') $product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : 0; $action = isset($_POST['action']) ? $_POST['action'] : ''; [ 'options' =>