title: How do i populate a dropdown list by selecting the value from another dropdown list?
body: <p>I have been trying to populate the contents of one drop down list with the selection of an item in another, using php,html and mysql database and Its proved to be a lot harder than i thought for me. I'm trying to get one dropdown list show names of all mobile phones based on company selections in the first drop down list.</p>
  
  <p>The code i've provided below has no errors, but the 2nd dropdown list is not getting populated. the variable '$submittedValue' is not getting the right value and hence '$name' also has no content in it. I can't seem to be able to figure out a reason for this.</p>
  
  <p>what i've done is, to try to use the selected option in the first drop down list, put that into a variable and pass that as a parameter to the 2nd query.</p>
  
  <p>I solution to this would be greatly appreciated.      </p>
  
  <pre><code>&lt;?php
  
   $con=mysqli_connect("localhost","root","","dbmobiles");
  
   // Check connection
   if (mysqli_connect_errno($con)) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
  
   $options = '';
   $submittedValue = '';
   $name=" ";
  
   $q1=mysqli_query($con,"select distinct compName from umobile order by compName ASC");
   while($row = mysqli_fetch_array($q1)) {
      $options .="&lt;option value=". $row['compName'] ." &gt;" . $row['compName'] .    "&lt;/option&gt;";
   }
  
   $menu1 = "&lt;form id='filter' name='filter' method='post' action=' '&gt;    
             &lt;p&gt;&lt;label&gt;Select Company&lt;/label&gt;&lt;/p&gt;
             &lt;select name='filter' id='filter'&gt;
             " . $options . "
             &lt;/select&gt;
            &lt;/form&gt;";
  
   if (isset($_POST["filter"])) {
      $submittedValue = $_POST["filter"];
   }
   echo $menu1;
  
   if ($q2=mysqli_prepare($con,"SELECT DISTINCT mobname FROM umobile WHERE compName=? "))
   {
      mysqli_stmt_bind_param($q2,"s",$submittedValue);
      $s=$submittedValue;
      mysqli_stmt_execute($q2);
      mysqli_stmt_bind_result($q2,$r);
   }  
  
   while(mysqli_stmt_fetch($q2)) {
      $name .="&lt;option&gt;".$r['mobname']."&lt;/option&gt;";
   }
  
   echo ".$name.";
   $menu2 = "&lt;form id='moblist' name='moblist' method='post' action=' '&gt;
              &lt;p&gt;&lt;label&gt;Select Mobile&lt;/label&gt;&lt;/p&gt;
              &lt;select name='moblist' id='moblist'&gt;
              " . $name . "
              &lt;/select&gt;
             &lt;/form&gt;";
  
   echo $menu2;
  ?&gt;
  </code></pre>