title: Multiple database populated dropdowns -- how to retrieve values via POST
body: <p>I am very close to finishing a project I've been working on, thanks to the good folks at Stack Overflow. Yay! I've already looked at similar questions but they don't address it in the context of multiple dropdowns: <strong>how do I submit a form with both selected values from a database in a dropdown as well as dropdowns without?</strong> The dynamically generated values ('city', 'state') are not being posted. Part of the form:</p>
  
  <pre><code>&lt;select name="city[]" id="city" multiple&gt;
  &lt;?php
  $query="SELECT City FROM Cities";
      $result = mysqli_query($link, $query);
            while($r = mysqli_fetch_assoc($result)){
              echo '&lt;option value="'.$r['City'].'"&gt;'.$r['City'].'&lt;/option&gt;'; }
            ?&gt;
      &lt;/select&gt;
  </code></pre>
  
  <p>The results from the database successfully show up. And the second page, where I assemble the query: <strong>edit: updated</strong></p>
  
  <pre><code>            $where = array();
              $param = array();
                 foreach($_POST as $key =&gt; $option) {
                  if (
                      !empty($option)
                      and in_array($key, array('Role', 'issueInterest', 'targetPop','placement', 'targetIssues', 'City', 'state')))
                  {
                      if (is_array($option)) {
                          foreach($option as $k =&gt; $optval) {
                              $where[] = "`".$key."` = ?";
                              $param[] = $optval;
                          }
                      }
                      else {
                              $where[] = "`".$key."` = ?";
                              $param[] = $option;
                      }
                  }
              }
  
              $query_string = "SELECT * FROM dummy_table";
  
              if(!empty($where))
                  $query_string .= " WHERE ".implode(' AND ',$where);
  
              $stmt = $db-&gt;prepare($query_string);
              $stmt-&gt;execute($param);
              echo '&lt;pre&gt;';
              $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC);
              echo '&lt;center&gt;&lt;table cellpadding="0" cellspacing="0" class="db-table"&gt;';
            echo '&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;
                &lt;th&gt;Email:&lt;/th&gt;
            &lt;/tr&gt;
            &lt;/thead&gt;';
              while($row = $stmt-&gt;fetch()) {
                  echo "&lt;tr&gt;&lt;td&gt;";
              echo $row['name'];
              echo "&lt;/td&gt;&lt;td&gt;";
                echo $row['email'] . '&lt;/td&gt;';
              }
              echo '&lt;/pre&gt;';
              ?&gt;
  </code></pre>
  
  <p>If I choose someone from the database who is both a student (normal dropdown) and lives in New York(dynamic drop down), all students will be selected regardless of the city. </p>
  
  <p>If there is a better way to do this than PHP and mySQLi, let me know.
  Thank you!</p>