title: Function populates first listbox but not the second from a database table
body: <p>Function <code>popList()</code> takes two parameters - name of the column and name of the table.
  Basically the <code>popList(</code>) function connects to a <code>mysql</code> server and then a database and builds an sql query to retrieve data based on what you passed to the function to be used to populate a listbox on the page.</p>
  
  <p>Only one listbox works fine with the function, but if there's a second listbox on the page that calls the function again with different parameters(column name and table name) passed it appears empty and the following is printed in the source of the page right under the source of the first populated listbox:</p>
  
  <blockquote>
    <p><b>Warning</b>:  mysql_connect() [function.mysql-connect]: Access
    denied for user 'ODBC'@'localhost' (using password: NO) in
    <b>C:\xampp\htdocs\test</b> on line <b>7</b><br /> Not connected :
    Access denied for user 'ODBC'@'localhost' (using password: NO)</p>
  </blockquote>
  
  <p>I use the same connection credentials in both calls which are default localhost, root and no password(purely for testing purposes)</p>
  
  <p>Why is it behaving like this?</p>
  
  <p><strong>EDIT*</strong>(source)*:</p>
  
  <pre><code>&lt;?php
  function popList($col, $tbl) {
  
      require_once "credentials.php";
  
      // Opens a connection to a MySQL server
      $connection=mysql_connect($host, $username, $password);
      if (!$connection) {
        die('Not connected : ' . mysql_error());
      }
  
      // Set the active MySQL database
      $db_selected = mysql_select_db($database, $connection);
      if (!$db_selected) {
        die ('Can\'t use db : ' . mysql_error());
      }
  
      $sql = "SELECT $field FROM $table";
      $query = mysql_query($sql);
  
      while ($row = mysql_fetch_array($query)) {
          echo '&lt;option value="' . $row["$field"] . '"&gt;' . $row["$field"] . '&lt;/option&gt;';
      }
  
      mysql_close($connection);
  }
  ?&gt;
  </code></pre>
  
  <p><strong>SOLUTION</strong>:</p>
  
  <p><em>NEW</em>: Seems like using <code>require_once</code> and <code>include_once</code> causes the issue, but using <code>include</code> or <code>require</code> actually fixes the problem.</p>
  
  <p><strike>Replaced <code>require_once "credentials.php"</code> with the actual code from <code>credentials.php</code> like so</strike>:</p>
  
  <pre><code>function popList(...) {
  
  require "credentials.php"; // changed to require from require_once. same with include
  
  
  ...
  }
  </code></pre>