darknessmdk Posted June 11, 2008 Share Posted June 11, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/109788-multiple-field-post/ Share on other sites More sharing options...
widox Posted June 11, 2008 Share Posted June 11, 2008 Is your problem getting the form inputs in your code or into your database table? Did you try printing out your $_POST data? Also echo your vars while in those loops to make sure you're working with the correct data. Quote Link to comment https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-563452 Share on other sites More sharing options...
hansford Posted June 12, 2008 Share Posted June 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-563565 Share on other sites More sharing options...
darknessmdk Posted June 12, 2008 Author Share Posted June 12, 2008 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'];" Quote Link to comment https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-564159 Share on other sites More sharing options...
hansford Posted June 12, 2008 Share Posted June 12, 2008 start with just getting the values, then you can add other code. There is no key =>value as the array is not associative. <?php if(isset($_POST['list2'])){ foreach($_POST['list2'] as $key){ echo $key . '<br>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109788-multiple-field-post/#findComment-564397 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.