I posted this on another forum so it might save time if i paste what we covered so far
I am just stuck on the last section as i seem to be passing the same ID each time instead of the unique one.
Hi
Any help would be awesome...
I have a form that displays 5 records in a recordset. Each record has an image and a drop down menu and the unique ID. The drop down menu is the state and can be on or off.
By default all states are set to on but what i am trying to do is have it so the users can turn off what they want using the drop down menus and press one submit button to update the state to what they have chosen from the drop down menus.
I was able to use an array for an insert statement using checkboxes from a form, but i am struggling with this one.
I am using the code I had from the insert array tweaked a little. This will update one of the records from the recordset but not the remaining 4.
The form field names are:
selectID (this is the unique ID)
box1[] (this is the state drop down menu, can be on or off)
pic (this is just an image)
Code: Select all
PHP<?
$box=$_POST['box1'];
$selectID=$_POST['selectID'];
$box_count=5;
foreach ($box as $dear) {
$selectID=$_POST['selectID'];
mysql_select_db($database_gdn, $gdn);
$query_Recordset1 = ("UPDATE pics_selected SET state = '$dear' WHERE selectID = '$selectID'");
$Recordset1 = mysql_query($query_Recordset1, $gdn) or die(mysql_error());
header("Location: games_accept.php");
}
?>selectID (this is the unique ID)
box1[] (this is the state drop down menu, can be on or off)
pic (this is just an image)
so
$box=$_POST['box1'];
is an array with the on or off... does it look something like
$box(
[0] => 1,
[1] => 0,
[2] => 0,
[3] => 1,
[4] => 1,
)
but what does
$selectID=$_POST['selectID'];
look like if you print_r($selectID)
because it looks like your passing only one id, thats why it'll update (guessing) the last one in the form.
You are correct. If i add print_r($selectID); into the loop then it prints out the final ID five times.
What would i need to change in order to pass each ID?