We have been given the task where we have to populate a drop down box with data from a database using PHP and MySQL etc. This is the code I have so far. So far since I have tested it, it is showing the drop down box but other than that there is nothing in the drop down menu populating it.
<?php
$hostname = 'host';
$username = 'username';
$password = 'password';
$databaseName = 'dbname';
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$query = 'SELECT * FROM `User`';
$result1 = mysqli_query($connect, $query);
$result2 = mysqli_query($connect, $query);
$options = '';
while ($row2 = mysqli_fetch_array($result2)) {
$options = $options . "<option>$row2[1]</option>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title> PHP SELECT OPTIONS FROM DATABASE </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<select>
<?php while ($row1 = mysqli_fetch_array($result1)):; ?>
<option value="<?php echo $row1[0]; ?>"><?php echo $row1[1]; ?> </option>
<?php endwhile; ?>
</select>
<select>
<?php echo $options; ?>
</select>
</body>
</html>