Jump to content

Multiple field post


darknessmdk

Recommended Posts

Okay, Here the problem, I have a table that is displaying rows from a database, the last column displays dropdown boxes that you can select yes or no, yes enables the account and no disables the account. I am having an issue capturing the data from these dropdown boxes.

I am storing the data in an array and using foreach loops, there the code.

 

The update part.

		<?
	if ($_POST ['button']=='update'){

	$checked = $_POST['id'];
	$checked2 = $_POST['list2'];

	foreach($checked as $key => $value){

	$scan = mysql_query("SELECT restid FROM restaurants WHERE restid = '$key'");

	while($srow = mysql_fetch_array($scan)) {

	foreach($checked2 as $key2 => $value2){
	echo "$value";
	$update = mysql_query("UPDATE restaurants SET ractive = '$value2' WHERE restid = '$key'");
			}
		}
	}
	if($update == TRUE) {
	echo "<br><span class='body_text'>Yes, I know this isn't working.</span>";
	}else{

	echo "<br><span style='color:#FF0000' class='body_text'>We have encountered an error, please try again. </span>";


		}
	}
	?>

 

this is the drop down box that is displayed in the form

 

<select name='list2[]' id='list2[]'>
              		<option value='$row[ractive]' selected='selected'>$row[ractive]</option>
                  <option value='Yes' >Yes</option>
                  <option value='No'>No</option>
                </select>

Link to comment
https://forums.phpfreaks.com/topic/109788-multiple-field-post/
Share on other sites

firstly, get rid of selected='selected' and no need for name='list2[]' as just 'list' will do

 

<select name='list2[]' id='list2[]'>

<option value='$row[ractive]' selected='selected'>$row[ractive]</option>

                  <option value='Yes' >Yes</option>

                  <option value='No'>No</option>

                </select>

 

to get the value selected it would be

$selected = $_POST['list2'];

the selected value will be whatever was selected. if nothing is selected it will default to the first option value listed in the form

Link to comment
https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-563565
Share on other sites

widox, I am having a problem getting the correct data into the database, It only echos one row id number 4 times.

 

 

hansford, I am storing the values in an array which is why i need "name='list2[]'" the "selected='selected'" is because I want that first option to be the default. 

 

If you check my code at the top I already have what you suggested to get the selected value

"$checked2 = $_POST['list2'];"

Link to comment
https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-564159
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.