当用户输入数量并单击“更新”时,我正在尝试调整项目的数量,但我无法让它工作。当您结束数量并单击更新时,它什么也不做。下面是我的php代码
PHP 代码
<?php start_session(); ?>
<?php
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
$item_to_adjust = $_POST['item_to_adjust'];
$quantity = $_POST['quantity'];
$quantity = preg_replace('#[^0-9]#i', '', $quantity);
if ($quantity >= 100) { $quantity = 99; }
if ($quantity < 1) { $quantity = 1; }
if ($quantity == "") { $quantity = 1; }
$i = 0;
foreach ($_SESSION["cart_array"] as $array_key=>$each_item) {
if ($each_item['item_id'] == $pid && $each_item['item_to_adjust'] == $item_to_adjust && $each_item['length'] == $length && $each_item['Category'] == $Category) {
$_SESSION["cart_array"][$array_key]['quantity']=$quantity;
$wasFound = true;
}
}
}
?>
形式
echo '<form action="cart.php" method="post">
<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
<input name="adjustBtn' . $item_id . '" type="submit" value="Update" />
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form>';
?>