-3
在此代碼刪除案例中執行的時間超過會話獲取負值。哪些類型的更改發生在代碼中,以獲得僅獲得正值的會話。如何停止會話轉爲負值?
<?php
session_start();
$d1=$_POST['d1'];
$action=$_POST['str1'];
$product_id = $_POST['productid'];
switch($action)
{
case "Add":
$_SESSION['cart'][$product_id] = $d1 + (isset($_SESSION['cart'][$product_id]) ?$_SESSION['cart'][$product_id] : 0);
break;
case "Remove":
$_SESSION['cart'][$product_id]=(isset($_SESSION['cart'][$product_id]) ? $_SESSION['cart'][$product_id] : 0)- $d1;
if($_SESSION['cart'][$product_id] == 0)
unset($_SESSION['cart'][$product_id]);
break;
}
?>
THX弗雷德-II-並請幫我在主邏輯 –
你那裏有'+號,我不確定這是否有效。嘗試使用'&&'代替。或者是用於計算? –
+ sign working .. and all code working .. when remove case more time than session get negative value ...這個主要概念 –