I am having difficulty returning data from my database to a dropdown menu inside of a HTML form using PHP. Connection to my works and doesnt appear to be the issue but not returning data from the table to the dropdown. Any ideas? Thanks
<!DOCTYPE html>
<html>
<body>
<?php
try {
$conn = new PDO("mysql:host=$localhost;dbname=dbname", "root", "password");
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$sql = "SELECT team_name FROM team;";
$result = mysqli_query($query,$conn) or var_dump(mysqli_error());
?>
<form action="">
First name:<br>
<input type="text" name="firstname" value="First">
<br>
Last name:<br>
<input type="text" name="lastname" value="Last">
<br><br>
<select name ="name" required>
<option selected disabled>--Select an option--</option>
<?php
while ($row = $result->fetch_array()) {
//echo "hi";
$optionecho = "<option>" ;
$optionecho .= $row['team_name'] ;
$optionecho .= "</option>";
print($optionecho) ;
} ?>
</select>