Add-cart.php Num May 2026

if (!$product_id || !$quantity) http_response_code(400); die(json_encode(['error' => 'Invalid product or quantity']));

<?php session_start(); if(isset($_GET['id']) && isset($_GET['num'])) $product_id = $_GET['id']; $quantity = $_GET['num']; // No validation! $_SESSION['cart'][$product_id] = $quantity; header('Location: cart.php'); ?> add-cart.php num

Use addslashes() or log in structured formats (JSON) with strict key validation. Building a Secure add-cart.php from Scratch Here is a production-ready example handling the num parameter securely: if (!$product_id || !$quantity) http_response_code(400)

Because the num parameter is not parameterized, the attacker can extract the entire database. Regardless of where num is used (validation, logging, or cart logic), use parameterized queries: 'Invalid product or quantity']))

Imagine a promotional rule: "Buy 2, get 1 free." The developer checks only if num >= 2 . An attacker sends: add-cart.php?id=promo_item&num=9999