Jump to content

Drop Down Menu + MySQL + PHP


bam2550

Recommended Posts

Okay well, i have a private messaging system. I am trying to fix up the send form... But im hitting some brick walls...

 

What my work looks like as of now!

upload_183.jpg

 

Question:

1) How do i set a value to a drop down menu so it sends the selected information (POST) to send.php

2) How do i make it so Subject is not invisible, and on the line below the drop down menu.

 

Thanks thats it!

 

Here is what you might need:

 

form.html

<html>
<select>
<?php

$con = mysql_connect("localhost","3434","45345");

mysql_select_db("login", $con);

$result = mysql_query("SELECT * FROM users", $con);


while($row = mysql_fetch_array($result))
{
  ?> 

Send to: <option><?php echo $row['username']; ?></option>
  <?php
    }
?>
<form action="send.php" method="POST">
<br>
Subject: <br><input type="text" name="sub">
<br>
Your Message: <br><textarea name="msg" rows="10" cols="45"></textarea><br>
<input type="submit" value="Send">
</form>
<?php
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
</select>
</html>

 

This is what i want the drop down menu to be set to...

 

 $sendto = trim(mysql_real_escape_string($_POST["to"])); 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/105044-drop-down-menu-mysql-php/
Share on other sites

<select><option></option></select> must be all inside the form. Use value="someValue" in the <option> tag to assign a value to that option. Use name="to" to assign a name to the <select> so u can call it with post. Your code should look:

 

<html>
<form action="send.php" method="POST">
<select name="to">
<?php

$con = mysql_connect("localhost","3434","45345");

mysql_select_db("login", $con);

$result = mysql_query("SELECT * FROM users", $con);


while($row = mysql_fetch_array($result))
{
  ?> 

Send to: <option value="<?php echo $row['username']; ?>"><?php echo $row['username']; ?></option>
  <?php
    }
?>
</select>
<br>
Subject: <br><input type="text" name="sub">
<br>
Your Message: <br><textarea name="msg" rows="10" cols="45"></textarea><br>
<input type="submit" value="Send">
</form>
<?php
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
</html>

Okay, one small problem and one small thing to say!

 

The one small thing is i didnt want a value, i just got my words mixed up :)

 

The one small problem is that in my text editor (linux ubuntu, which usually always colors PHP syntax) is not coloring in my PHP stuff, only HTML... I think this is affecting the code since the script does not work now...

 

This is my form...

 

<html>
<form action="send.php" method="POST">
<select name="to">
<?php

$con = mysql_connect("localhost","3434","45345");

mysql_select_db("login", $con);

$result = mysql_query("SELECT * FROM users", $con);


while($row = mysql_fetch_array($result))
{
  ?> 

Send to: <option> <?php echo $row['username']; ?> </option>
  <?php
    }
?>
</select>
<br>
Subject: <br><input type="text" name="sub">
<br>
Your Message: <br><textarea name="msg" rows="10" cols="45"></textarea><br>
<input type="submit" value="Send">
</form>
<?php
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
</html>

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.