Jump to content

Dropdown select - INSERT


karimali831

Recommended Posts

Hi

 

Hoping someone can help me with this.

I am trying to insert rows into my table from multiple dropdown selection.

 

Problem is when I submit the form, I don't get userID - &action=insertlineup&clanID=11&cupID=2&userID=

clanID will always be one value, but userID can be multiple so not sure how to work round this.

 

userID is from the value of the options.

 

Options - get members:

		$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>'; };

 

Form:

		$form = 'Ctrl+Left click to select/deselect
	  <tr bgcolor="'.$bg1.'">
	    <td align="right" bgcolor="'.$bg1.'">Select Lineup:</td>
	    <td bgcolor="'.$bg2.'"><select name="member" onChange="MM_confirm(\'Are you sure with your selection?\', \'?site=clans&action=insertlineup&clanID='.$clanID.'&userID=\'+this.value)" size="5" multiple>'.$member2.'</select> <form action="?site=clans&action=insertlineup&clanID='.$clanID.'&userID='.$dr['userID'].'" method="POST"><input type="submit" value="Enter Selected" /> </form> </td>
	  </tr>';	} echo $form;

 

 

Query:

}if(isset($_GET['action']) && $_GET['action'] == 'insertlineup') {
if(isleader($userID,$_GET['clanID'])){
	safe_query("UPDATE ".PREFIX."cup_clan_lineup SET clanID = '".$_GET['clanID']."' && userID = '".$_GET['userID']."' WHERE cupID = '".$_GET['cupID']."'");	
	redirect('?site=clans&action=mylineup&clanID='.$_GET['clanID']', 'Redirecting...', 2);		
}

 

Look at attatchment for example:

 

Wraith - value = 6 (userID)

-X1-Lite - value = 256 (userID)

 

I want both these userID inserted

clanID and cupID don't matter as only one is needed.

 

If this is not possible, any other way to select specific rows from a table and insert into another table?

 

Hope you understand, thanks for any help.

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Query:

 

}if(isset($_GET['action']) && $_GET['action'] == 'insertlineup') {
   if(isleader($userID,$_GET['clanID'])){
      safe_query("UPDATE ".PREFIX."cup_clan_lineup SET clanID = '".$_GET['clanID']."' && userID = '".$_GET['userID']."' WHERE cupID = '".$_GET['cupID']."'");   
      redirect('?site=clans&action=mylineup&clanID='.$_GET['clanID']', 'Redirecting...', 2);      
   }

 

Form:

 

      $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>';

      $form = 'Ctrl+Left click to select/deselect
        <tr bgcolor="'.$bg1.'">
          <td align="right" bgcolor="'.$bg1.'">Select Lineup:</td>
          <td bgcolor="'.$bg2.'"><select name="member" size="5" multiple>'.$member2.'</select> <form action="?site=clans&action=insertlineup&clanID='.$clanID.'&userID='.$dr['userID'].'" method="POST"><input type="submit" value="Enter Selected" /> </form> </td>
        </tr>';   } echo $form;

Link to comment
Share on other sites

you can see $form echos outside the loop and ain't I going to need the loop because I want to insert multiple userID?

 

Changed it to

 

	  $form = '
	                            <form action="index.php">
                                <input type="hidden" name="site" value="clans">
                                <input type="hidden" name="action" value="insertlineup">
                                <input type="hidden" name="clanID" value="'.$clanID.'">
                                <input type="hidden" name="cupID" value="'.$cupID.'">
                             <select name="userID" size="5" multiple>
                             '.$member2.'
                             </select>
                          <input type="submit" value="Go" onclick="return confirm(\'Are you sure with your selection? \');">
                       </form>'; } echo $form;

 

Output: &action=insertlineup&clanID=11&cupID=2&userID=68&userID=320

 

with this output can it insert like this:

 

clanID = 11 AND userID = 320

clanID = 11 AND userID = 68

clanID = 11 AND cupID = 2

 

that's all I want.

Link to comment
Share on other sites

you can see $form echos outside the loop and ain't I going to need the loop because I want to insert multiple userID?

 

In that case your going to need to append each iteration onto the $form variable. Otherwise, its only ever going to show the last record. You still should have your <form></form> tags outside the loop so you end up with one formm

 

And you can't have two keys with the same name within the $_GET array.

Link to comment
Share on other sites

Can you show me how to do this please?

 

Here is what I got so far:

 

$cupID = $_GET['cupID'];

  //get members in team
  
  $members = safe_query("SELECT clanID FROM ".PREFIX."cup_clan_members WHERE userID='$userID'");
  while($dd=mysql_fetch_array($members)) {

  //get team in cup
  
    $registered = safe_query("SELECT clanID FROM ".PREFIX."cup_clans WHERE cupID='$cupID' && clanID='".$dd['clanID']."' && 1on1='0'");
    while($dm=mysql_fetch_array($registered)) { $clanID = $dm['clanID'];

  //get members
	$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>'; 

  //dropdown		

	if(isleader($userID,$clanID))	{
	 $form = 'Ctrl+Left click to select/deselect
	  <form action="index.php">
            <input type="hidden" name="site" value="clans">
            <input type="hidden" name="action" value="insertlineup">
            <input type="hidden" name="clanID" value="'.$clanID.'">
            <input type="hidden" name="cupID" value="'.$_GET['cupID'].'">
            <select name="userID" size="5" multiple>
             '.$member2.'
            </select><br>
           <input type="submit" value="Enter Selected" onclick="return confirm(\'Are you sure with your selection? \');">
	  </form>'; 
	  
	  echo '<br> userID = '.$dr['userID'].'';
	  
	  if(isset($_GET['action']) && $_GET['action'] == 'insertlineup') {
	  
	safe_query("INSERT INTO ".PREFIX."cup_clan_lineup (cupID, clanID, userID) VALUES ('$cupID', '$clanID', '".$dr['userID']."')");	
	redirect('?site=clans&action=mylineup&cupID='.$_GET['cupID'].'&clanID='.$_GET['clanID'], 'Lineup Successful! You may change it before cup starts.', 2);
	      }	
	    }
	  } 
	} 
  }echo $form;

 

echo '<br> userID = '.$dr['userID'].'';

 

Output:

 

userID = 68

userID = 320

 

safe_query("INSERT INTO ".PREFIX."cup_clan_lineup (cupID, clanID, userID) VALUES ('$cupID', '$clanID', '".$dr['userID']."')");

 

Output:

 

Only one row -

cupID = 12, clanID = 11, userID = 320

I want to have also:

cupID = 12, clanID = 11, userID = 68

 

 

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.