Your HTML is broken - you can't put a FORM tag inside a SELECT tag.
Haven't spotted any other obvious problems (but then I haven't done much PHP recently, so could easily be missing something).
Also it's generally a bad idea to mix business logic with display logic - do all your database lookups first, then do the display stuff with minimal PHP/looping second.
For example:
PHP code: <?php
$db_name = "dsm";
$table_name = "dsm_names";
$connection = mysql_connect("localhost", "dsm", "1234")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id,first,last FROM $table_name ORDER BY first";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<form method="post" action="form.php">
<select name="user">
<?php
while ($row = mysql_fetch_array($result))
{
$user_name = trim("$row['first'] $row['last']");
echo "<option value=\"".$row['id']."\">".$user_name."</option>\n ";
}
?>
</select>
<input type="Submit" name="Submit" value="Submit Form" />
</form>
Still not perfect, but probably good enough. :) |