title: Second dependent dropdown isn't getting filled with data
body: <p>I'm trying to make a grade distributions website, and I'm creating 4 dropdowns correlating subject (cs, math, etc.), class (data structures, AI, etc.), professor, and quarter the class was taken. After the quarter dropdown is selected, I want to display a bar graph with the data.</p>
  
  <p><strong>The problem I'm running into is that I can't populate the second dropdown with data</strong> Basically, I can successfully pull data from the database for the first dropdown, and if the user selects something then the second dropdown (that was originally hidden using jquery) becomes visible, but it isn't properly pulling data from the database and adding it as options to the second dropdown. An example would be that I can select Computer Science from the first dropdown, then the second dropdown is visible, but it doesn't contain 'intro to programming', 'data structures', etc. in it; instead, it's just blank.  </p>
  
  <p>FYI, I'm using these selectpickers: <a href="http://silviomoreto.github.io/bootstrap-select/" rel="nofollow">http://silviomoreto.github.io/bootstrap-select/</a></p>
  
  <p>PHP (error is most likely somewhere in the getClasses function, quite possibly the $_POST section of the code):</p>
  
  <pre><code>&lt;?php   
  
  function getSubjects()
  {   
      /* Get mysql connect information from external file and connect*/
      require_once 'database.php'; 
      $connection = new mysqli($db_hostname, $db_username, $db_password, $db_database);
      if($connection-&gt;connect_error) die ($connection-&gt;connect_error);
  
      /* Get the column containing the subjects from the table */
      $query = 'SELECT DISTINCT Subject FROM gradelist ORDER BY Subject';
      $result = $connection-&gt;query($query);
  
      if(!$result) die ($connection_error);
  
      /* Keep track of the number of rows in the column; necessary for iterating */
      $rows = $result-&gt;num_rows;
  
      /* selectBar keeps track of the html code for the select Bar*/
      $selectBar = '';
  
      for($j = 0; $j &lt; $rows; $j++)
      {
          $result-&gt;data_seek($j);
          $value = $result-&gt;fetch_assoc()['Subject'];
          $selectBar .= '&lt;option&gt;' . $value .'&lt;/option&gt;';     
      }
  
      $result-&gt;close();
      $connection-&gt;close();
  
      return $selectBar;
  }
  
  
  function getClasses()
  {
      $connection = new mysqli($db_hostname, $db_username, $db_password, $db_database);
      if($connection-&gt;connect_error) die ($connection-&gt;connect_error);
  
      if(isset($_POST['subject']))
      {
          $query = "SELECT DISTINCT Class FROM gradelist WHERE Subject = $subject";
          $result = $connection-&gt;query($query);
          if(!$result) die ($connection_error);
      }
      else
      {
          die($connection_error);
      }
  
      $rows = $result-&gt;num_rows;
  
      for($j = 0; $j &lt; $rows; $j++)
      {
          $result-&gt;data_seek($j);
          $value = $result-&gt;fetch_assoc()['Class'];
          $selectBar .= '&lt;option value = "' . $value . '"&gt;' . $value .'&lt;/option&gt;';        
      }
      $result-&gt;close();
      $connection-&gt;close();
  
      return $selectBar;
  }   ?&gt;
  </code></pre>
  
  <p>HTML Portion of the code (again, the error might be with the $_POST part of the code) : </p>
  
  <pre><code>            &lt;form class="form-horizontal" method = "post" role="form"&gt;
                  &lt;div class="form-group"&gt;
                    &lt;div class="col-lg-10"&gt;
                      &lt;select name = "subject" id="subject" class="selectpicker show-tick form-control" data-live-search="true" title ="Subject"&gt;
                          &lt;?php echo getSubjects(); ?&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
  
  
                &lt;form class="form-horizontal" method = "get" role="form"&gt;
                  &lt;div class="form-group"&gt;
                    &lt;div class="col-lg-10"&gt;
                      &lt;select name = "class" id="class" class="selectpicker show-tick form-control" data-live-search="true" title ="Class"&gt;
                          &lt;?php if(isset($_POST['subject'])) echo getClasses(); ?&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/form&gt;
  </code></pre>
  
  <p>jQuery: </p>
  
  <pre><code>$(document).ready(function() {
  
  $('#class').selectpicker('hide');
  $('#professor').selectpicker('hide');
  $('#quarter').selectpicker('hide');
  });
  
  $('#subject').on('change', function(){
      $('#class').selectpicker('refresh');
      $('#class').selectpicker('show');
  });
  $('#class').on('change', function(){
      $('#professor').selectpicker('show');
  });
  $('#professor').on('change', function(){
      $('#quarter').selectpicker('show');
  });
  $('#quarter').on('change', function(){
      showTable();
      temp = $('#class').selectpicker('val') + " with " + $('#professor').selectpicker('val') + " during " + $('#quarter').selectpicker('val');
      $('#displayName').text(temp);
  });
  </code></pre>