Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.