使用PHP和mysqli从数据库中获取Selectbox值

I want to pick up peoples names from a phpmyadmin database and place them in a HTML select box, when the user picks a name from the select box it should display the detail from the database for that person in a table. I can't seem to get this to work, I can get the names to pick up from the database and display in a select box but when you click on the name it seems to bring up every record in the database rather than just the one for that person. I am using mysql rather than mysql. Here is my code

This is my back end stuff

<?php 
$conn = mysqli_connect("localhost", "root", "root") or die ("No connection"); 
mysqli_select_db($conn, "flat") or die("db will not open"); 
$query = "select FlatCode, Address from FLAT"; 
$result = mysqli_query($conn, $query) or die("Invalid query"); 
echo "<table border='1'><tr><th>modulecode</th><th>studentnum</th></tr>";  
while($row = mysqli_fetch_array($result)) 
{ 
    echo "<tr><td>" . $row[0] .  "</td><td>" .  $row[1] .  "</td></tr>";
} 
echo "</table>"; 
mysqli_close($conn); 
?> 

this is my front end stuff

<font size="4"> Choose an Owner Name</font><br><br> 
<form action="flat.php" method="post"> 
<select name="name"> 
<?php 
$con = mysqli_connect("localhost", "root", "root") or die ("No connection"); 
mysqli_select_db($con , "flat") or die ("db will not open"); 
$query = "SELECT distinct OwnerName, FlatCode, Address from FLAT"; 
/*$query= $_POST ("name")
function change_guery($query)
mysqli_use_result*/

$result = mysqli_query($con, $query) or die("Invalid query");  
while($rows = mysqli_fetch_array($result))

{ 
      echo "<option value=\"" . $rows[0] . "\">" . $rows[0] . "</option>"; 
} 

echo "</select>"; 
           

mysqli_close($con); 
?> 
<input type="submit" value="Submit Value"> 
</form></body></html> 

</div>

There is a problem in your flat.php code. You are posting the the info correctly via form but you forgot to receive it via $_POST in flat.php.

See the following code and comments in it, it should work -

<?php 
$n = $_POST["name"];//we receive the name passed by the form
$conn = mysqli_connect("localhost", "root", "root") or die ("No connection"); 
mysqli_select_db($conn, "flat") or die("db will not open"); 
$query = "select FlatCode, Address from FLAT WHERE `OwnerName` = '$n' LIMIT 1";//see the changes here 
$result = mysqli_query($conn, $query) or die("Invalid query"); 
echo "<table border='1'><tr><th>modulecode</th><th>studentnum</th></tr>";  
$row = mysqli_fetch_array($result);
//as the result will return 1 row only so we dont need while loop here
echo "<tr><td>" . $row[0] .  "</td><td>" .  $row[1] .  "</td></tr>";
echo "</table>"; 
mysqli_free_result($result);//dont forget to free result
mysqli_close($conn); 
?>