I'm having difficulty populating a select box within a form to display existing "forenames" of nurses from the "Nurses" table. Could anyone tell me what Im doing wrong? Thanks in advance!
Here is the form
<form method="post" action="insert.php">
<br>
<tr><td align="left"><strong>Nurse Information</strong></td>
</td>
<tr>
<td>nurse_name</td>
<td><select name="valuelist">
<option value="valuelist" name="nurse_name" value='<?php echo $nurse_name; ?>'></option>
</select></td>
<tr>
The QUERY which should populate the nurse_forename:
<html><head><title>Connect to Database</title></head><body>
<font size="4">Query gets Forename of nurse</font>
<br><br><font size="4">Choose a name</font><br><br>
<form action="insert.php" method="post">
<select name="valuelist">;
<?php
$value=$_POST ["valuelist"];
$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("a&e", $con) or die('Could not select database.');
$fetch_nurse_name = mysql_query("SELECT DISTINCT $nurse_name FROM nurse");
$result = mysqli_query($con, $query) or die("Invalid query");
while($throw_nurse_name = mysqli_fetch_array($fetch_nurse_name)) {
echo '<option value=\"'.$nurse_name['nurse_name'].'">'.$throw_nurse_name['nurse_name'].'</option>';
}
echo "</select>";
mysqli_close($con);
?>
<input type="submit" value="Submit">
</form></body></html>
Try this:
Dont use mysql and mysqli together....you should use mysqli or PDO, but not a mix of both ;) PS: Edited ;)
Saludos.
Apologies if this duplicates other answers, Here's an answer using mysql_ syntax although you should of course be using mysqli_ or PDO for this...
Check your MySQL table and column name that you using. Sometimes it does not work if you don't write those names exactly which in your MySQL table. suppose,
in above SQL if MySQL table name is 'NURSE' and column name is 'NURSE_NAME' then write exactly like this.
So, you look that sometime MySQL table, column name work in case sensitive.