0
我目前正在尝试创建购物车并通过$ _SESSION变量发送它。更新与更多变体的购物车
但是,当我尝试通过$ _POST更新项目时,它只会更新购物车中的最后一个产品。
这里是我的形式
<form method="post">
<?php foreach ($_SESSION['cart'] as $product) {
$productDetail = Products::getProduct($product['id']);
?>
<input type="hidden" name="id" value="<?= $product['id']; ?>">
<input name="qty" size="5" maxlength="50" type="text" value="<?= $product['quantity']; ?>">
<input name="width" size="5" maxlength="50" type="text" value="<?= $product['width']; ?>">
<input name="length" size="5" maxlength="5" type="text" value="<?= $product['length']; ?>">
<?php } ?>
<input type="submit" value="send" />
</form>
在这里,我如何更新我的购物车
$item_id = $data['id'];
$quantity = $data['qty'];
$width = $data['width'];
$length = $data['length'];
$_SESSION['cart'][$item_id]['quantity'] = $quantity;
$_SESSION['cart'][$item_id]['width'] = $width;
$_SESSION['cart'][$item_id]['length'] = $length;
它总是更新形式,只有最后一个。
是否有解决这个问题的方法? 我会非常appriciate它。
谢谢。
非常有帮助,谢谢。 :)) – George 2015-04-02 10:17:57