我之前有连接等;我试图提取的列在数据库课程中称为course_name - 不确定我是否遗漏了某些内容?
<label for="course">Related Course</label>
<select name="course" class="form-control">
<?php
$result = mysql_query($conn, "SELECT course_name FROM course");
echo "<select name='course_name'>";
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
while ($row = mysql_fetch_array($result1)) {
echo "<option value='" . $row['course_name'] ."'>" . $row['course_name'] ."</option>";
}
}
echo "</select>";
?>
</select>
答案 0 :(得分:0)
所以从你下面的评论中你使用的是mysqli而不是mysql php扩展,所以你的代码看起来应该是这样的
<?php
$result = mysqli_query($conn, "SELECT course_name FROM course");
echo "<select name='course_name'>";
if (!$result) {
die('Invalid query: ' . mysqli_error($conn));
} else {
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['course_name'] ."'>" . $row['course_name'] ."</option>";
}
}
echo "</select>";
?>