I've got a session called Cart_array
which holds a multidimensional array in the following way:
$_SESSION['Cart_array'] = array(
1 => array(
"ID" => $pid,
"QTY" => 1
)
);
this is how items are added to the cart session. pid
is obtained from another form
if (isset($_POST['pid'])) {
$pid = $_POST['pid'];
if (!isset($_SESSION['Cart_array']) || count($_SESSION['Cart_array']) < 1) { //check if cart session is not set or empty
$_SESSION['Cart_array'] = array(
1 => array(
"ID" => $pid,
"QTY" => 1
)
);
} else {
array_push($_SESSION['Cart_array'], array(
"ID" => $pid,
"QTY" => 1
));
} //end else
} //end if
the user has a form with the following things in a function:
<?php foreach ($_SESSION['Cart_array'] as $eachItem) {
$itemID = $eachItem['ID'];
$itemQty = $eachItem['QTY']; >?
<input class="qty" name="quantity" type="number" value="<?php echo $itemQty;?>" />
<input type="submit" name="qtyChange<?php echo $itemID;?>" value="Change Qty" />
<input name="qtyOfItem" type="hidden" value="<?php echo $itemID?>"/>
}
This form will go through the Cart_array
and display the quantity in the cart for every item.
I want the user to be able to change the quantity in the cart for the specific item that they chose when they click the Change Qty
button
I'm not sure how to go around doing this?