HELP! I have problems to get the search result from multiple drop down search menus. When I click "submit" button, it give me none data. The part of my codes are as follows:
<?php
$dblink=mysql_connect("localhost","username","password")
or die("Could not connect to the database, please try later");
mysql_select_db ("dbname",$dblink)
or die ("Could not select database");
function q_r($query, $dblink) {
$r = mysql_query ($query,$dblink)
or die ("Query failed");
while ($row=mysql_fetch_array($r))
{ for($i=0; $i<mysql_num_fields($r); $i++)
printf("<option>%s</option>\n",($row[$i]));
}
mysql_free_result ($r);
}
if(!$_POST['submit']) {
echo '<form method="POST">';
echo '<br>';
echo '<b>Host</b>';
echo '<select name="hostfield">';
$query1="SELECT DISTINCT host FROM table";
$q1_r=q_r($query1,$dblink);
echo '</select>';
echo '<b>Program</b>';
echo '<select name="programfield">';
$query2="SELECT DISTINCT program FROM table";
$q2_r=q_r($query2,$dblink);
echo '</select>';
echo '<b>Facility</b>';
echo '<select name="facility field">';
$query3="SELECT DISTINCT facility FROM table";
$q3_r=q_r($query3,$dblink);
echo '</select>';
echo '<input type="submit" name="submit" value="submit">';
echo '<br><br>';
echo '</form>';
} else {
$hostId=$POST['host'];
$programId=$POST['program'];
$facilityId=$_POST['facility'];
$q="SELECT date,time,host,msg FROM logs WHERE host='$hostId'
AND program='$programId' AND facility='$facility'"
or die("failed");
$result = mysql_query($q,$dblink);
while($row = mysql_fetch_assoc($result)) {
printf
}
}
?>
Is there anyone can tell me where is wrong with the code? OR how to get the selected data from the search menu? Thanks a lot!