ok so what im trying to do is, IF a button is pressed, update the data already on the page and if a certain condition is satisfied, also echo out a message. -
//if the UPDATE TOTAL button is pressed
if (isset($_POST) && $_POST['update'] == "Update Total") {
$quantityarray = $_POST['quantity'];
$idarray = $_POST['id'];
foreach ($quantityarray as $key => $quantity) {
if ($quantity == 0 || $quantity == "") {
mysql_query("DELETE from basket WHERE sessid = '$session' AND prodid = '".$id[$key]."'") or die(mysql_error());
?><meta http-equiv="refresh" content="0"><?php
} else {
//STOCK CHECK
$checkstock = mysql_query("SELECT * from products WHERE id = '".$id[$key]."'") or die(mysql_error());
$check_stock_item = mysql_fetch_assoc($checkstock);
if ($check_stock_item['numstock'] < $quantity) {
echo ("Sorry, We only have ".$check_stock_item['numstock']." ".$check_stock_item['productname']." left in stock!");
} else {
mysql_query("UPDATE basket SET quantity = '$quantity' WHERE sessid = '$session' AND prodid = '".$id[$key]."'") or die(mysql_error());
?><meta http-equiv="refresh" content="0"><?php
}
}
}
}
Yeaaa I can see the obvious problem with this- ie that surely the meta refresh on the first loop should stop everything because it sends ya back to the beginning of the page, but oddly that ISNT whats happening. what is, is that I seem to be getting a refresh at the end of the loop- which is fine because I do need to refresh the page there to display updated stock, but I also need to display the message if theres none left in stock, n of course refreshing negates this. Ive tried a million variations on this code but it always comes out the same.. seems I cant have a refresh AND echo a message, so question is, is there any way this is possible?