3

我很难在表单中填充选择框以显示“护士”表中现有的护士“名字”。谁能告诉我我做错了什么?提前致谢!

这是表格

 <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>  

应填充nurse_forename 的QUERY:

<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>
4

3 回答 3

1

试试这个:

<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 Forename FROM nurse");


while($throw_nurse_name = mysql_fetch_array($fetch_nurse_name)) {
echo '<option   value=\"'.$throw_nurse_name[0].'">'.$throw_nurse_name[0].'</option>';
}
echo "</select>";


?>
<input type="submit" value="Submit">
</form></body></html>

不要同时使用 mysql 和 mysqli ......你应该使用 mysqli 或 PDO,但不能同时使用两者;) PS:已编辑;)

萨卢多斯。

于 2013-02-15T13:17:10.447 回答
0

抱歉,如果这与其他答案重复,这是使用 mysql_ 语法的答案,尽管您当然应该为此使用 mysqli_ 或 PDO...

 <form action="insert.php" method="post">
 <select name="valuelist">;
 <?php

 //path to connection statements
 include('path/to/connection/stateme.nts'); 

 //fetch nurse name
 $query = "SELECT nurse_name FROM nurse;";

 $result = mysql_query($query) or die(mysql_error()); //note: use mysql_error() for development only

 //print results
 while($row = mysql_fetch_assoc($result)) {
 echo '<option   value=\"'.$row['nurse_name'].'">'.$row['nurse_name'].'</option>';
 }
 echo "</select>";

  ?>
 <input type="submit" value="Submit">
 </form>
于 2013-02-15T13:23:15.610 回答
0

检查您使用的 MySQL 表和列名。有时,如果您没有在 MySQL 表中准确地写出这些名称,则它不起作用。认为,

$query = "SELECT nurse_name FROM nurse";

在上面的 SQL 中,如果 MySQL 表名是 'NURSE' 并且列名是 'NURSE_NAME' 则完全像这样写。

$query = "SELECT NURSE_NAME FROM NURSE";

因此,您有时会看到 MySQL 表、列名区分大小写。

于 2013-09-24T16:30:28.183 回答