I have been trying to create a form with dynamic dropdown list fetching data from MYSQL. My database is fine without errors. I have been trying to make it work, the page does not take data from mysql, what's wrong with my code? The table is called 'table' and the column is called "name", there are three inputs "name1", "name2", "name3", but they are not fetched from mysql. Thank You.
<?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>