我正在创建一个可以查询多个字段的搜索 - 搜索一个有助听器的男性。
表单中的 html 代码如下所示
<form name="O_search" method="post" action="search.php">
Gender (M/F)<input type="text" name="O_gender"/>
Hearing Aid (Y/N)<input type="text" name="O_hear"/>
<input type="hidden" name="O_searching" value="yes" />
php代码看起来像这样
if (isset($_POST['O_searching'] ))
{
echo "<h2>Results</h2><p>";
if (isset($_POST['O_gender']) || isset($_POST['O_hear']) == "")
{
echo "You forgot to enter a search term";
exit;
}
$Gender =$_POST['O_gender'];
$Hear =$_POST['O_hear'];
$Gender = strtoupper($Gender);
$Gender = strip_tags($Gender);
$Gender = trim ($Gender);
$Hear = strtoupper($Hear);
$Hear = strip_tags($Hear);
$Hear = trim ($Hear);
$Odata = mysql_query("SELECT * FROM p_candidate WHERE(`gender` LIKE '%".$Gender."%') AND (`hear` LIKE '%".$Hear."%')") or die(mysql_error());
while($result = mysql_fetch_array($Odata))
{
$candidate_id =$result['candidate_id'];
echo "<tr>";
echo "<td><a href ='opening_candidatepage.php?id=$candidate_id'>".$result['R_first_name']." ".$result['R_last_name']."</td>";
echo "<td>".$result['R_county']."</td>";
}
$anymatches=mysql_num_rows($Odata);
if ($anymatches == 0)
{
echo "Sorry, there is no match for your query<br><br>";
}
echo "<b>Searched For:</b> " .$Gender." and".$Hear ;
}
?>
我不知道我哪里出错了,但即使我在字段中输入了有效的搜索词,我也会收到消息您忘记输入搜索词