我正试图使用一个按钮来更新我所有的购物车数量,但它不起作用
我已通过会话将产品添加到购物车,现在显示购物车中的产品只是想更新数量,而不是更新
if(isset($_POST["updates"])) {
if(isset($_SESSION["shopping_cart"])) {
$pid=$_POST['proid'];
$qty =$_POST['quantity'];
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['item_id'] == $_POST['proid']) {
$_SESSION['shopping_cart'][$key]['item_qty'] = $_POST['quantity'];
}
}
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
header('Refresh:0');
}
}
@RiggsFolly这是打印结果
Array (
[0] => Array (
[item_id] => 24
[item_name] => something
[item_price] => 800
[item_qty] => 1
)
[1] => Array (
[item_id] => 26
[item_name] => Fishly
[item_price] => 450
[item_qty] =>
)
)