車項目的最大數量這是我添加項目到購物車php腳本:
session_start();
require_once("dbcontroller.php");
$db_handle = new DBController();
switch($_GET['action']) {
case 'add':
$productByCode = $db_handle->runQuery("SELECT item, brand, price, catalog FROM products WHERE catalog='".$_GET['catalog']."'");
$itemArray = array($productByCode[0][‘catalog']=>array(
'item'=>$productByCode[0]['item'],
'brand'=>$productByCode[0]['brand'],
'price'=>$productByCode[0]['price'],
'catalog'=>$productByCode[0]['catalog']));
if(!empty($_SESSION['cart_item'])) {
if(!in_array($productByCode[0]['catalog'],($_SESSION['cart_item']))) {
$_SESSION['cart_item'] += $itemArray;
}
}
else {
$_SESSION['cart_item'] = $itemArray;
}
我想車項目的最大數量限制爲20 ,這意味着即使用戶點擊添加按鈕時沒有在$ _session中找到新項目,購物車項目已達到20,新項目將不會再添加。有沒有辦法做到這一點?請幫助。提前致謝。
首先,請停止與任何亂搞那甚至遠遠與任何購物功能有關,只要你還沒有學會如何應對SQL注入...... – CBroe
其次,你究竟是什麼意思 - 20個不同數量的數量不同(後者無關緊要),或總數20的時候訂購的數量加起來? – CBroe
20個不同數量的不同數量,酷男,我只是在這裏學習。即使那個腳本我從人的教程 –