我正在爲學生創建一個頁面,他們可以通過三種不同的選項搜索他們的結果。我有問題。請指引我在哪裏,我在做什麼錯誤在搜索結果中遇到困難php
<form action="do_search.php" method="post">
<table width="540" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30"><strong>Search Criteria</strong></td>
<td></td>
<td><label for="criteria"></label>
<select name="criteria" id="criteria">
<option>Seach by Name</option>
<option>Search by Father Name</option>
<option>Search by Roll No.</option>
</select></td>
</tr>
<tr>
<td height="30"> </td>
<td></td>
<td> </td>
</tr>
<tr>
<td width="150" height="30"><strong>Enter Value:</strong></td>
<td width="20"></td>
<td width="370"><input name="value" type="text" id="value" size="40" /></td>
</tr>
<tr>
<td height="10" colspan="3"></td>
</tr>
<tr>
<td height="30"></td>
<td></td>
<td>
<input name="submit" type="submit" value="Submit" id="submit_btn"/>
<input name="reset" type="reset" value="Reset" id="reset_btn" /> </td>
</tr>
<tr>
<td colspan="3" height="10"></td>
</tr>
</table>
</form>
do.search.php
<?php
include 'authentication.php';
include 'includes/dbConnect.php';
?>
<?php
$criteria = $_POST['criteria'];
$value = $_POST['value'];
if ($value == '')
{
$myURL = 'error.php?eType=no_value';
header('Location: '.$myURL);
exit;
}
if ($criteria == "search by name")
{
$result = mysql_query("SELECT * FROM students WHERE Name = '$value'") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
}
elseif ($criteria == "search by father name")
{
$result = mysql_query("SELECT * FROM students WHERE Father_Name = '$value'") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
}
elseif ($criteria == "search by roll no.")
$result = mysql_query("SELECT * FROM students WHERE Roll_No. = '$value'") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
?>
請指引我哪裏做錯了。
一切存在於這個問題,我們需要,除了你的錯誤是什麼。請向我們提供您收到的錯誤。 – Ohgodwhy 2014-09-25 04:39:38
要獲得多個搜索結果的名稱,你必須使用 like子句 - 「SELECT * FROM students WHERE Father_Name like'%$ value'」 – justrohu 2014-09-25 04:40:21