please why is the loop statement breaking, after the multiplication it only update the last row, tried using a foreach loop for the $totalprice in the update statement it says invalid argument.
if(array_key_exists('item', $_POST)){
// $items = $_POST['item'];
//foreach($_POST['item'] as $item){
//echo $item['Pquantity'] . ", ";
//echo $item['Pidno'] . ", ";
// }
//Loop through $_POST items, updating the database for each item
foreach ($_POST['item'] as $item) {
$Pquantity = intval($item['Pquantity']);
$Pidno = ($item['Pidno']);
//echo $Pquantity . ", ";
//echo $Pidno . ", ";
//$totalprice = intval($item['Pquantity'])
$queryreg = mysql_query("
UPDATE repplac
SET Pquantity = {$Pquantity}
WHERE
Pidno = '{$Pidno}'
AND
Uname = '{$_SESSION['username']}'
") or die(mysql_error());
}
}
$pplresult = mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
while ($row = mysql_fetch_assoc($pplresult))
{
$totalprice = $row['Price'] * $row['Pquantity'];
//echo "$totalprice";
//die();
$queryreg = mysql_query("
UPDATE repplac
SET Tprice = {$totalprice}
WHERE
Pidno = '{$Pidno}'
AND
Uname = '{$_SESSION['username']}'
") or die(mysql_error());
}
Inside your
foreachyou update$Pidnowith the following codeThus you are updating different records in the database. But inside your
whileloop$Pidnois staying the same the entire time. Thus you are updating the same record over and over. To fix this add the following code at the beginning of thewhileloop