title: Dynamic multi-level drop down using MySQL DB
body: <p>I am trying to create a multi level drop down menu hopefully using PHP since I have no prior experience in javascript but I am willing to learn that also. To make this easy for everyone to understand I am using cars as and example. I want the user to select a "Brand" example Ford, then a second drop down will populate with the "Models" Ford has made and finally a third drop down will populate with "Colors" of Ford vehicles. I am using a MySQL database that I want to pull all of the data from dynamically instead of hardcoding the values in. I am able to get the first drop down to populate with the "Brands" but when I select a "Brand" the second drop down does not populate with the new results. I am new to PHP and MySQL but a very quick learner. Here is my code:</p>
  
  <p>INSERT_DROPDOWN.PHP</p>
  
  <pre><code> &lt;?php
  $con = mysql_connect("localhost","username","XXXXXXXXXX");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  
  mysql_select_db("database", $con);
  
  // Write out BRANDS.
  $dquery = "SELECT brand FROM manufacture ORDER BY brand";
  // Execute it, or return the error message if there's a problem.
  $dresult = mysql_query($dquery) or die(mysql_error());
  
  // Write out MODELS.
  $dquery1 = "SELECT 'brand', 'model' FROM models WHERE brand='$dresult' ORDER BY model";
  // Execute it, or return the error message if there's a problem.
  $dresult1 = mysql_query($dquery1) or die(mysql_error());
  
  
  // Write out COLORS.
  $dquery2 = "SELECT color FROM color ORDER BY color";
  // Execute it, or return the error message if there's a problem.
  $dresult2 = mysql_query($dquery2) or die(mysql_error());
  
  // if successful insert data into database, displays message "Successful". 
  if($dresult){
  echo "Successful";
  echo "&lt;BR /&gt;";
  }
  
  else {
  echo "ERROR1";
  }
  
  // close connection 
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>TESTING.PHP</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
              &lt;LINK href="CLL.css" rel="stylesheet" type="text/css"&gt;
          &lt;title&gt; 
             testing
          &lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
  &lt;?php 
  require "insert_dropdown.php";
  ?&gt;
  
  &lt;p&gt;
    &lt;?php
      //Brand
      $dropdown = "&lt;select name='brand'&gt;";
        while($row = mysql_fetch_assoc($dresult)) 
      {
  
      $dropdown .= "\r\n&lt;option value='{$row['brand']}'&gt;{$row['brand']}&lt;/option&gt;";
  
      }
  
      $dropdown .= "\r\n&lt;/select&gt;";
      echo $dropdown;
  
      //Model
          $dropdown1 = "&lt;select name='brand'&gt;";
        while($row1 = mysql_fetch_assoc($dresult1)) 
      {
  
      $dropdown1 .= "\r\n&lt;option value='{$row1['model']}'&gt;{$row['brand']}&lt;/option&gt;";
  
      }
  
      $dropdown1 .= "\r\n&lt;/select&gt;";
      echo $dropdown1;
  
      //Color
          $dropdown = "&lt;select name='name'&gt;";
        while($row = mysql_fetch_assoc($dresult2)) 
      {
  
      $dropdown .= "\r\n&lt;option value='{$row['color']}'&gt;{$row['color']}&lt;/option&gt;";
  
      }
  
      $dropdown .= "\r\n&lt;/select&gt;";
      echo $dropdown;
    ?&gt;
  &lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>