jaredclance Posted October 22, 2007 Share Posted October 22, 2007 Ok, so what I am trying to do, is populate a drop down list with nicknames from the database, then the user will select a name, hit approve and it will update the selected person in the database. All of my code works, and if I insert a specific name into the approval query it works, I just don't know how make the update query know which name I have selected from the drop down. It all works, I just don't know what to put for the update query NickName, I bolded the part that I am unsure about. $approvalQuery = mysql_query("SELECT ID, NickName, Coach_Name, Email FROM `Profiles` WHERE Status='Approval' AND `Coach_Name`='{$p_arr['Coach_Name']}'"); $nameQuery = mysql_query("SELECT Coach_Name, NickName, Status FROM `Profiles` WHERE `ID`='{$p_arr['ID']}'"); $arrName = mysql_fetch_assoc( $nameQuery ); ?> </td> </tr> <? if ($arrName["Coach_Name"] == $arrName["NickName"]){ ?> <tr> <td>Approvals: </td> <td> <? echo "<select name=\"NickName\">"; echo "<option size =30 selected>Select</option>"; if(mysql_num_rows($approvalQuery)) { while($myrow = mysql_fetch_assoc($approvalQuery)) { echo "<option>$myrow[NickName]</option>"; } } else { echo "<option>No Names Present</option>"; } ?> </td> </tr> </td> <td valign="top" align="left" class="control_panel_td_2"> <form method="post" action="member.php"> <input type="submit" value="Approve" name="Approve"> <input type="submit" value="Deny" name="Deny"> </form> </td> <? }else{ echo "No Pending Students"; } ?> </tr> <? //Approves user account activation if(isset($_POST['Approve'])) { mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/ Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 No, instead of $myrow['NickName'] it would be $_POST['NickName']; Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375612 Share on other sites More sharing options...
jaredclance Posted October 22, 2007 Author Share Posted October 22, 2007 Still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375615 Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 Try setting a value on the option, <option value=\"$myrow[NickName]\">$myrow[NickName]</option> Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375618 Share on other sites More sharing options...
jaredclance Posted October 22, 2007 Author Share Posted October 22, 2007 That's what I was thinking too. Gave it a try, and it still doesn't work. I just don't know how to select the specific options from the drop down dynamically. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375619 Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 I see your problem, your drop down menu isn't inside your form. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375620 Share on other sites More sharing options...
jaredclance Posted October 22, 2007 Author Share Posted October 22, 2007 But if I change the update query to something like //Approves user account activation if(isset($_POST['Approve'])) { mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = 'jared'") or die (mysql_error()); } Instead of //Approves user account activation if(isset($_POST['Approve'])) { mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error()); } Then it all works exactly how I want it to. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375621 Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 But then it's not going to post the nickname you selected in your dropdown menu, like i said, its not you MySQL query, its your HTML your dropdown menu isn't inside the <form> tags. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375623 Share on other sites More sharing options...
jaredclance Posted October 22, 2007 Author Share Posted October 22, 2007 Still doesn't work <form method="post" action="member.php"> <? echo "<select name=\"NickName\">"; echo "<option size =30 selected>Select</option>"; if(mysql_num_rows($approvalQuery)) { while($myrow = mysql_fetch_assoc($approvalQuery)) { echo "<option>$myrow[NickName]</option>"; } } else { echo "<option>No Names Present</option>"; } ?> </td> </tr> </td> <td valign="top" align="left" class="control_panel_td_2"> <input type="submit" value="Approve" name="Approve"> <input type="submit" value="Deny" name="Deny"> </form> </td> <? }else{ echo "No Pending Students"; } ?> </tr> <? //Approves user account activation if(isset($_POST['Approve'])) { mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$myrow['NickName']}'") or die (mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375624 Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 <form method="post" action="member.php"> <? echo "<select name=\"NickName\">"; echo "<option size =30 selected>Select</option>"; if(mysql_num_rows($approvalQuery)) { while($myrow = mysql_fetch_assoc($approvalQuery)) { echo "<option>$myrow[NickName]</option>"; } } else { echo "<option>No Names Present</option>"; } ?> </td> </tr> </td> <td valign="top" align="left" class="control_panel_td_2"> <input type="submit" value="Approve" name="Approve"> <input type="submit" value="Deny" name="Deny"> </form> </td> <? }else{ echo "No Pending Students"; } ?> </tr> <? //Approves user account activation if(isset($_POST['Approve'])) { mysql_query("UPDATE Profiles SET Status = 'Active' WHERE Status='Approval' AND NickName = '{$_POST['NickName']}'") or die (mysql_error()); } You have to set the $_POST[] array, not the $myrow[] array. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375626 Share on other sites More sharing options...
jaredclance Posted October 22, 2007 Author Share Posted October 22, 2007 Thanks, you're a life saver. Quote Link to comment https://forums.phpfreaks.com/topic/74340-solved-posting-from-a-drop-down/#findComment-375629 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.