//the form from which my vars come
while($each_item = mysql_fetch_array($get_items_query)) {
echo ("...some stuff... <input type='hidden' name='id[]' value='".$each_item['id']."'>
<input type='text' size='2' maxlength='6' name='stock[]' value='".$each_item['numstock']."'>... more stuff...");
}
$stock = $_POST['stock'];
$id = $_POST['id'];
//make sure none of the fields are empty
foreach ($stock as $stockarray) {
if ($stockarray == "") {
echo ("<b>You cannot leave any fields empty! Update Aborted.</b>");
exit; }
//new loop to update the database if first loop is ok.
foreach ($id as $idarray) {
mysql_query("UPDATE products SET numstock = '$stockarray' WHERE id = '$idarray'") or die(mysql_error());
}
Ok so I haveeee a form thats created dynamically by pulling data from a database. basically im pulling up data from each product on my list, n sticking the current values in an editable text field. Then once the submit button is pressed i want to grab all of the vars in the "stock" field and update them to the posted vars. thats what I have so far. it works upto the last loop with the update in.. where it grabs the last posted stock number n puts it in every field instead of sticking each one in the field with the corrisponding id.. yes I realise this is what Im telling it to do, but I dont know what it should be? Im pretty sure its the "foreach ($id as $idarray) thats wrong...