title: Getting Selectbox values from the database using PHP and mysqli
body: <p>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</p>
  
  <p>This is my back end stuff</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?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 "&lt;table border='1'&gt;&lt;tr&gt;&lt;th&gt;modulecode&lt;/th&gt;&lt;th&gt;studentnum&lt;/th&gt;&lt;/tr&gt;";  
  while($row = mysqli_fetch_array($result)) 
  { 
      echo "&lt;tr&gt;&lt;td&gt;" . $row[0] .  "&lt;/td&gt;&lt;td&gt;" .  $row[1] .  "&lt;/td&gt;&lt;/tr&gt;";
  } 
  echo "&lt;/table&gt;"; 
  mysqli_close($conn); 
  ?&gt; </code></pre>
  </div>
  </div>
  </p>
  
  <p>this is my front end stuff</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;font size="4"&gt; Choose an Owner Name&lt;/font&gt;&lt;br&gt;&lt;br&gt; 
  &lt;form action="flat.php" method="post"&gt; 
  &lt;select name="name"&gt; 
  &lt;?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 "&lt;option value=\"" . $rows[0] . "\"&gt;" . $rows[0] . "&lt;/option&gt;"; 
  } 
  
  echo "&lt;/select&gt;"; 
          
  
  mysqli_close($con); 
  ?&gt; 
  &lt;input type="submit" value="Submit Value"&gt; 
  &lt;/form&gt;&lt;/body&gt;&lt;/html&gt; </code></pre>
  </div>
  </div>
  </p>