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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
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.