Siggles Posted February 18, 2009 Share Posted February 18, 2009 I have a form that is sending the following POST array to another page .. Key: markedinv10; Value: 10 Key: markedinv11; Value: 11 Key: markedinv19; Value: 19 Key: markedinv20; Value: 20 Key: x; Value: 6 Key: y; Value: 8 Key: opt; Value: updateinv I want to run a loop of UPDATE statements to a MySQL database updating the rows a field matches the value of every key in the array starting with markedinv... (the x and y are for the submit image and the opt key is for a switch statement). So for example: foreach ($_POST as $key => $val){ while ($key == markediv^){ $query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' "); } Can I loop an update statement first of all and if so what php can I use to check for markedinv^ and get the $val from them? many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/145763-array-foreach-and-update/ Share on other sites More sharing options...
Siggles Posted February 18, 2009 Author Share Posted February 18, 2009 I changed the form to this <input name=\"markedinv[]\" then the processing page to this foreach ($_POST['markedinv'] as $key => $val){ echo "Key: $key; Value: $val<br />\n"; $query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' "); } which works to tick the boxes. Yay! Now I need to work out how to untick the boxes (or make the value of marked_invoice to 0 instead of to 1)!! Quote Link to comment https://forums.phpfreaks.com/topic/145763-array-foreach-and-update/#findComment-765309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.