karimali831 Posted July 1, 2010 Share Posted July 1, 2010 When I select ALL options in a dropdown and post the form, I echo $_POST['value'] and it echos the last value in the dropdown. I want it to echo all the ones I have selected. It echos the correct one when I select only one, but selecting multiple will echo the last one in dropdown region? So was thinking what I need to get all the selected post values.. array? Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/ Share on other sites More sharing options...
AbraCadaver Posted July 1, 2010 Share Posted July 1, 2010 <select name="my_select[]" multiple="multiple"> Then you have an array of: $_POST['my_select'] Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/#findComment-1079904 Share on other sites More sharing options...
Psycho Posted July 1, 2010 Share Posted July 1, 2010 You need to name the select field so it is interpreted by PHP as an array, i.e. you need to add brackets to the name <select name="fieldname[]"> The value $_POST['fieldname'] will be available in the receiving page and will be an array of all the selected values. Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/#findComment-1079906 Share on other sites More sharing options...
karimali831 Posted July 2, 2010 Author Share Posted July 2, 2010 Hmm I must be doing something wrong then: Form <form method="post" action="index.php?site=clans&action=lineup&cupID='.$_GET['cupID'].'&do=insert&clanID='.$clanID.'&userID='.$dr['userID'].'"> <input type="hidden" name="site" value="clans"> <input type="hidden" name="action" value="lineup"> <input type="hidden" name="do" value="insert"> <input type="hidden" name="cupID" value="'.$_GET['cupID'].'"> <input type="hidden" name="clanID" value="'.$clanID.'"> <select name="userID[]" size="5" multiple="multiple"> '.$member2.' </select><br> <input type="submit" value="Enter Selected" onclick="return confirm(\'Are you sure with your selection? \');"> </form>'; Option $members2=safe_query("SELECT userID FROM ".PREFIX."cup_clan_members WHERE clanID = '$clanID' && function!='Leader'"); while($dr=mysql_fetch_array($members2)) { $member2.='<option value="'.$dr['userID'].'">'.getnickname($dr['userID']).'</option>'; When I don't use the array, name="userID" is posted from single option. When I do use array, name="userID[]" no userID posts? The userID's I want posted in an array is this: <option value="'.$dr['userID'].'"> - the ones I select. Thanks for help. Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/#findComment-1080142 Share on other sites More sharing options...
karimali831 Posted July 2, 2010 Author Share Posted July 2, 2010 This should make it more clear: Options: $members=safe_query("SELECT userID FROM ".PREFIX."cup_clan_members WHERE clanID = '$clanID' AND userID != '$userID'"); while($dv=mysql_fetch_array($members)) { $member.='<option value="'.$dv['userID'].'">'.getnickname($dv['userID']).'</option>'; Form: <form method="post" action="index.php?site=clans&action=lineup&cupID='.$_GET['cupID'].'&clanID='.$clanID.'&do=insert"> <select name="member[]" size="5"multiple"> '.$member.' </select><br> <input type="submit" value="Enter Selected" onclick="return confirm(\'Are you sure with your selection? \');"> </form>'; Query: safe_query("UPDATE ".PREFIX."cup_clan_members SET cupID = '".$_GET['cupID']."' WHERE userID = '".$_POST['member']."' && clanID = '".$clanID."'"); echo 'post userID = '.$_POST['member'].''; Output: userID = Array userID = Array echo 'userID = '.$dv['userID'].''; Output: userID = 68 userID = 320 It doesn't UPDATE the table with array is my problem. Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/#findComment-1080148 Share on other sites More sharing options...
karimali831 Posted July 2, 2010 Author Share Posted July 2, 2010 I had to use foreach(){$query} Solved. Quote Link to comment https://forums.phpfreaks.com/topic/206438-select-multiple-post/#findComment-1080153 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.