Reputation: 5
I've got a login form which I'm trying to simplify. It all worked when you manually inputted your username and password. Now I am wanting a drop down for the username box from the MySql database.
This is the code that I have put into the form and it drops down and shows all the users but when you select it, put the password in and click login it doesn't pass the username.
<?php
mysql_connect('localhost', 'user', 'password.');
mysql_select_db('database');
$sql = "SELECT username FROM users";
$result = mysql_query($sql);
echo "<select username='sub1'>";
while ($row = mysql_fetch_array($result)) {
echo"<option value'" . $row['username'] ."'>" . $row['username'] ."</option>"; } echo "</select>";?>
Any Ideas Anyone
Thanks
Upvotes: 0
Views: 54
Reputation: 2967
replace your code with this:
<?php
mysql_connect('localhost', 'user', 'password.');
mysql_select_db('database');
$sql = "SELECT username FROM users";
$result = mysql_query($sql);
echo "<select name='sub1'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['username'] ."'>" . $row['username'] ."</option>";
}
echo "</select>";
?>
Upvotes: 0
Reputation: 3034
Tom, always check your generated HTML to investigate errors.
Change your code to:
<?php
mysql_connect('localhost', 'user', 'password.');
mysql_select_db('database');
$sql = "SELECT username FROM users";
$result = mysql_query($sql);
echo "<select name='username'>"; // Note name attribute
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['username'] ."'>" . $row['username'] ."</option>"; // Note `=` sign after value
}
echo "</select>";
?>
Upvotes: 2