複数のフィールドを照会できる検索を作成しています - 補聴器を持っている男性を検索します。
フォームの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 ;
}
?>
どこで間違ったのかわかりませんが、フィールドに有効な検索用語を入力しても、「検索用語を入力するのを忘れました」というメッセージが表示されます