I am trying to adjust the quantity of an item when a user enters the quantity and click on Update but I am having a problem getting it to work. When you end the quantity and click on update, it does nothing. Below is my php code
PHP code
<?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;
}
}
}
?>
FORM
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>';
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…