Only one select list works on PHP form
<p><strong>Disclaimer: It's been a while since I last wrote any code. The quality of my code is likely to be sub-par. You've been warned.</strong></p>

<p>I have a basic form that's meant to search flat files on our server. The "search engine" I created as two select lists: one for the file names and one for the customer site files come from.</p>

<p>For a reason I can't figure out, whatever option I select from the second select list is never captured when I hit Submit. </p>

<p>However, whatever option I select from the first select list is always captured. </p>

<p>What am I missing? I am sure it's starting right at me.... Any hints welcome. Thank you.</p>

<p>Here's my code:</p>

<pre><code>&lt;HTML&gt;
&lt;head&gt;&lt;title&gt;SEARCH TOOL - PROTOTYPE&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;&lt;h1&gt;SEARCH TOOL - PROTOTYPE&lt;/h1&gt;
&lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
&lt;fieldset&gt;
&lt;legend&gt;Filename (one item)&lt;/legend&gt;&lt;select name="DBFilename" id="DBFilename"&gt;
&lt;?php $con = mysql_connect("localhost",  "user", "pass"); if (!$con) {  die('Could not connect: ' . mysql_error());}
mysql_select_db("dev", $con) or die(mysql_error());
$result = mysql_query("select distinct filename from search_test");
while ($row = mysql_fetch_array($result))
{ ?&gt;    &lt;option value="&lt;?php echo $row['filename']; ?&gt;"&gt;&lt;?php echo $row['filename']; ?&gt;&lt;/option&gt; &lt;?php } mysql_close($con); ?&gt;
&lt;/select&gt;&lt;/fieldset&gt;
&lt;fieldset&gt;
&lt;legend&gt;Site (one item)&lt;/legend&gt;&lt;select name="DBSite" id="DBSite"&gt;
&lt;?php $con = mysql_connect("localhost",  "user", "pass"); if (!$con) {    die('Could not connect: ' . mysql_error());}
mysql_select_db("dev", $con) or die(mysql_error());
$result = mysql_query("select distinct site from search_test");
while ($row = mysql_fetch_array($result))
{ ?&gt;        &lt;option value="&lt;?php echo $row['site']; ?&gt;"&gt;&lt;?php echo $row['site']; ?&gt;&lt;/option&gt; &lt;?php } mysql_close($con);
?&gt;
&lt;/select&gt;&lt;/fieldset&gt;
&lt;input type="submit" name="submit" value="submit" &gt;
&lt;input type="button" value="Reset Form" onClick="this.form.reset();return false;" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/HTML&gt;
&lt;?php

if (isset($_POST['submit'])) {

        if (!empty($_POST['DBFilename'])) {doFileSearch();}
                elseif (!empty($_POST['DBSite'])) {doSite();}
}

function doFileSearch() {
$mydir = $_SERVER['DOCUMENT_ROOT'] . "/filedepot";
$dir = opendir($mydir);
$DBFilename = $_POST['DBFilename'];

$con = mysql_connect("localhost", "user", "pass");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("dev", $con) or die("Couldn't select the database.");

$getfilename = mysql_query("select filename from search_test where filename='" . $DBFilename . "'") or die(mysql_error());

echo "&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Results.&lt;/td&gt;&lt;/tr&gt;";
while ($row = mysql_fetch_array($getfilename)) {
                $filename = $row['filename'];
                echo '&lt;tr&gt;&lt;td&gt;&lt;a href="' . basename($mydir) . '/' . $filename . '"  target="_blank"&gt;' . $filename . '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
        }
                echo "&lt;/table&gt;&lt;/body&gt;";
}

function doSite() {
$mydir = $_SERVER['DOCUMENT_ROOT'] . "/filedepot";
$dir = opendir($mydir);
$DBSite = $_POST['DBSite'];

$con = mysql_connect("localhost", "user", "pass");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("dev", $con) or die("Couldn't select the database.");

$getfilename = mysql_query("select distinct filename from search_test where site='" . $DBSite . "'") or die(mysql_error());

echo "&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Results.&lt;/td&gt;&lt;/tr&gt;";
while ($row = mysql_fetch_array($getfilename)) {
                $filename = $row['filename'];
                echo '&lt;tr&gt;&lt;td&gt;&lt;a href="' . basename($mydir) . '/' . $filename . '"  target="_blank"&gt;' . $filename . '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
        }
                echo "&lt;/table&gt;&lt;/body&gt;";

}
?&gt;
</code></pre>
