00stuff Posted December 13, 2011 Share Posted December 13, 2011 Hi guys, I am trying to create a script that gets a multiple select form selections and assign them to variables with php via the POST method. This is my code: <select name="search_commodity[]" multiple="multiple" size="3" style="position:absolute; top:80px; left:414px; " > <option value="all">All</option> <option value="none">None</option> <option value="some">Some</option> </select> Then after the form gets submited then it should go to this php page and the first value of the chosen options has to be assigned to the variable called commo. The problem is that is is not assigning anything. <?php $commo = $_POST['search_commodity[0]']; ?> Can someone help please? I can't figure it out. Link to comment https://forums.phpfreaks.com/topic/253116-how-to-get-multiple-select-values-through-post-on-php/ Share on other sites More sharing options...
xyph Posted December 13, 2011 Share Posted December 13, 2011 It will return an array. Multi-dimensional arrays are in the format $array['key']['subkey'] so you'd want to use $_POST['whatever'][0] That will only get you the first selected value though. You may want to read more about arrays here http://php.net/manual/en/language.types.array.php You may also want to read about the control structure, foreach. It's one of the easier ways to traverse through an array. Link to comment https://forums.phpfreaks.com/topic/253116-how-to-get-multiple-select-values-through-post-on-php/#findComment-1297628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.