Trying to populate a dropdown list from my database - connection is ok and in my mind the code I have should work, but currently getting a blank dropdown... Have looked at PHP- Fetch from database and store in drop down menu html as well as other tutorials but alas no luck so far!
code is as follows...
<?php
//get constants for database
require("database.php");
// Opens a connection to a MySQL server
$connection = mysqli_connect ($server, $username, $password);
if (!$connection){
die('Not connected : ' . mysqli_error());
}
// Set the active MySQL database
$db_selected = mysqli_select_db($connection, $database);
if (!$db_selected) {
die ('Can\'t use db : ' . mysqli_error($connection));
}
$query = "SELECT * FROM route WHERE 1";
$result = mysqli_query($connection, $query);
echo '<select name="list" style="width:400px;">';
while($r = mysqli_fetch_assoc($result)){
echo "<option value=".$r['alt']."</option>";
}
echo '</select>';
?>