我已經成功地使用PHP編寫了搜索引擎,使用php代碼搜索
經過測試,有一件事情讓我困擾。
第一個錯誤
(mysql_fetch_array() expects parameter 1 to be resource, boolean given in)
二錯誤
(mysql_num_rows() expects parameter 1 to be resource, boolean given in)
很抱歉,但我們無法找到一個條目,以符合您查詢......
這裏的代碼
<?php
echo "<h2>Search Results:</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "Account_Number")
{
echo "<p>You forgot to enter a search term!!!";
exit;
}
// Otherwise we connect to our Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
// We perform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM memaccounts WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array($data))
{
echo $result['Account_Number'];
echo $result['Name'];
echo "<br>";
echo $result['Balance'];
echo "<br>";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query...<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
//}
?>
拜託他lp,謝謝
*旁註:*停止使用廢棄的'mysql_ *'功能。改用MySQLi或PDO。 – Raptor
您的查詢失敗。 –
如果您的第一個查詢失敗,您如何「成功」編寫了搜索引擎? – GolezTrol