title: PHP/MySQL Dropdown
body: <p>I'm just learning PHP/MySQL and have spent the last few days trying to get a drop-down menu to populate options from my database. I have read through several tutorials, and tried to apply them, but I cannot get this working. </p>
  
  <p><strong>What I'm trying to do:</strong>
  I need a drop-down menu called "Genotype" that pulls a list of genotypes from the "Genotype" column of a table in my database named "Mice." </p>
  
  <p><strong>Problem</strong>: When I hit the submit button, it connects to my database and performs the query. BUT I cannot get any options to show up from the drop-down menu.</p>
  
  <p><strong>Here's my code so far (Please let me know if I should post mousecount.php)</strong></p>
  
  <pre><code>&lt;?php
  
  include('connection.txt');
  
  $conn = mysqli_connect($server, $user, $pass, $dbname, $port)
  or die('Error connecting to MySQL server.');
  ?&gt;
  
  &lt;html&gt;  
  &lt;head&gt;&lt;title&gt;Crap That Won't Work&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  
  &lt;hr&gt;
  &lt;dt&gt;THINGS ARE TOTALLY NOT WORKING&lt;/dt&gt;
  &lt;dd&gt;
  &lt;form action="mousecount.php" method="POST"&gt;
  &lt;table&gt;&lt;tr&gt;
  &lt;td&gt;&lt;p&gt;&lt;label for="Genotype"&gt;Genotype:&lt;/label&gt;&lt;br/&gt;
  &lt;select name="Genotype"&gt;
  &lt;?php
  $query = "SELECT MouseID, Genotype FROM Mice";
  $result = mysqli_query($conn, $query);
  while($row = mysqli_fetch_array($result))
  {
  print "&lt;option value=\"$row['Genotype']\"&gt;".$row['Genotype']."&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;/p&gt;&lt;/td&gt;
  &lt;/tr&gt;&lt;/table&gt;&lt;br/&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br /></p>
  
  <h1>Edit (solved):</h1>
  
  <p>I was having trouble getting the drop-down menu to populate with options from MySQL database. Thanks to your help. I'm posting my final code in case it will help anyone else.  </p>
  
  <pre><code>&lt;!-- Connect to database --&gt;
  &lt;?php
  include('connection.php');
  $conn = mysqli_connect($server, $user, $pass, $dbname, $port)
  or die (mysql_error());
  ?&gt;
  
  &lt;hr&gt;
  
  &lt;h4&gt;Mice Count&lt;/h4&gt;
  &lt;form action="mousecount.php" method="POST"&gt;
  &lt;p&gt;&lt;label for="Genotype"&gt;By Genotype:&lt;/label&gt;&lt;br/&gt;
  &lt;?php
  $query = "SELECT Genotype from Mice GROUP BY Genotype";
  $result = mysqli_query($conn, $query);
  echo "&lt;select name='Genotype'&gt;";
  echo "&lt;option value='0'&gt;-Select-&lt;/option&gt;";
  while($row = mysqli_fetch_array($result)) {
      echo "&lt;option value='".$row['Genotype']."'&gt;".$row['Genotype']."&lt;/option&gt;";
  }
  echo "&lt;/select&gt;";
  ?&gt;
  &lt;/p&gt;
  &lt;input type="submit" value="Submit"&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>