onthespot Posted July 8, 2009 Share Posted July 8, 2009 Ok i have a fully functional messaging system. I am now trying to get all the usernames into the TO field on the new message page. The idea is a drop down will allow you to select a username to send a message to. This is the code for newmessage.php that involves the drop down $res=mysql_query("SELECT username FROM ".TBL_USERS.""); while($row=mysql_fetch_assoc($res)){ $username=$row['username']; } and <select name="message_to">To: <option value=<? echo $username?>"><? echo $username?></option></select> <br> Any ideas where I am going wrong here, would really appreciate it, I think it is a basic mistake. thankyou Link to comment https://forums.phpfreaks.com/topic/165186-drop-down-php/ Share on other sites More sharing options...
rhodesa Posted July 8, 2009 Share Posted July 8, 2009 it should just be: To: <select name="message_to"> <?php $res=mysql_query("SELECT username FROM ".TBL_USERS."") or die(mysql_error()); while($row=mysql_fetch_assoc($res)){ $username=htmlspecialchars($row['username']); echo "<option value=\"$username\">$username</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/165186-drop-down-php/#findComment-871016 Share on other sites More sharing options...
onthespot Posted July 8, 2009 Author Share Posted July 8, 2009 Hey that works perfect, thankyou very much. Just a quick question, the session variable, $_SESSION['username', is of course defining the user logged in. How can I use that to stop the user being on that drop down list. In other words, stop them messaging themselves by their username not showing up on the list! Link to comment https://forums.phpfreaks.com/topic/165186-drop-down-php/#findComment-871020 Share on other sites More sharing options...
rhodesa Posted July 8, 2009 Share Posted July 8, 2009 $res=mysql_query("SELECT username FROM ".TBL_USERS." WHERE username != '".$_SESSION['username']."'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/165186-drop-down-php/#findComment-871024 Share on other sites More sharing options...
onthespot Posted July 8, 2009 Author Share Posted July 8, 2009 Awesome thankyou, learn more and more daily, so I never have to ask the same question twice, thankyou Link to comment https://forums.phpfreaks.com/topic/165186-drop-down-php/#findComment-871047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.