php
if(isset($_SESSION["basket_array"])){
foreach($_SESSION["basket_array"] as $each_item){
(mysql_query("UPDATE book SET copies=copies-1 WHERE bookid='$bookid'");
}
unset($_SESSION["basket_array"]);
header( 'Location: account.php' ) ;
}
Shopping Cart Update Stock I am updating my database using this php code. It is activated on button click. It takes the items in basket_array and using the $bookid it is meant to deduct 1 from the copies left in the database. But it only deducts from the last item in the array. e.g if there are 12 items in the basket it take twelve copies from last item in the basket. Thanks for the help. Ask me for more info if concept is not grasped.
Session Output $_SESSION["basket_array"]
array(2) {
[0]=> array(1) {
["bookid"]=> string(1) "1"
}
[1]=> array(1)
{ ["bookid"]=> string(1) "6"
}
}
$bookidinside your loop.$each_itemin your loop, but then using$bookidin your query. There's no way for someone to help fix this without knowing what the contents of$_SESSION["basket_array"]are.$bookid = $each_item['bookid']as the first line inside your loop.