Jump to content

Drop down php


onthespot

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

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