我一直在尝试创建一个具有动态下拉列表的表单,以从MYSQL提取数据。我的数据库很好,没有错误。我一直在尝试使其工作,该页面未从mysql接收数据,我的代码有什么问题?该表称为“表”,该列称为“名称”,有三个输入“ name1”,“ name2”,“ name3”,但它们不是从mysql获取的。谢谢。
<?php
$link=mysqli_connect("localhost","root","");
mysqli_select_db($link,"dropdown");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Connection is active" . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form name="form" action="" method="post">
<select>
<?php
$res = mysqli_query($link, 'SELECT name FROM table');
while($row = mysqli_fetch_array($res))
{
?>
<option><?php echo $row['name'];?></option>
<?php
}
?>
</select>
</form>
</body>
</html>