Jump to content

SELECT MULTIPLE POST


karimali831

Recommended Posts

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?

 

 

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

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.

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.

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.

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.