karimali831 Posted July 1, 2010 Share Posted July 1, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/ Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 Where is $dr defined? More relevant code would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079640 Share on other sites More sharing options...
karimali831 Posted July 1, 2010 Author Share Posted July 1, 2010 Sorry, updated my first code you can see now. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079642 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 These little snippets of code don't help, we need to see some context. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079644 Share on other sites More sharing options...
karimali831 Posted July 1, 2010 Author Share Posted July 1, 2010 Is that better? I now get one userID from the selection. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079646 Share on other sites More sharing options...
karimali831 Posted July 1, 2010 Author Share Posted July 1, 2010 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; Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079651 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 Your <select></select> tags are outside of the <form> tags so will never be sent with it. Also, your creating more than one form there by having it within the while() loop. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079656 Share on other sites More sharing options...
karimali831 Posted July 1, 2010 Author Share Posted July 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079668 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079672 Share on other sites More sharing options...
karimali831 Posted July 1, 2010 Author Share Posted July 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/206384-dropdown-select-insert/#findComment-1079681 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.