我有一個MySQL數據庫,我需要搜索交易號碼(並顯示我的姓名,電子郵件和item_name)或搜索我的電子郵件地址和名稱以及購買日期然後會給我我的交易號和item_name - 除非電子郵件,名稱和購買日期都是正確的,否則我不想要任何東西出現。搜索並顯示來自SQL數據庫的結果
場在我的數據庫是:
iname
iemail
itransaction_id
item_name
可能有人請幫助.... 這就是我目前有....
<html>
<head>
<title>Search</title>
</head>
<body bgcolor=#ffffff>
<h2>Search</h2>
<form name="search" method="post" action="findme.php">
Seach for: <input type="text" name="find" />
<input type="submit" name="search" value="Search" />
</form>
</body>
</html>
保存爲findme.html
下一個:
<html>
<head><title>Searching for a student...</title>
</head>
<body bgcolor=#ffffff>
<?php
echo "<h2>Search Results:</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term!!!";
exit;
}
// Otherwise we connect to our Database
mysql_connect("xxxx.com", "xxxx", "xxxxpw") or die(mysql_error());
mysql_select_db("xxxx") 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
$iname = mysql_query("SELECT * FROM ibn_table WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array($iname))
{
echo $result['firstname'];
echo " ";
echo $result['lastname'];
echo "<br>";
echo $result['idnumber'];
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($iname);
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;
//}
?>
</body>
</html>
這是保存爲findme.php
這是目前得到的錯誤IM:
搜索結果:
警告:mysql_fetch_array():提供的參數是不是一個有效的MySQL結果資源/愛馬仕/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php上線31
警告:mysql_num_rows():提供的參數不是在/hermes/bosweb25a/b409/ipg.bexgroupcouk/一個有效的MySQL結果資源silverliningnetworks/Database/findme.php on line 43 所以RRY,但我們無法找到一個條目,以符合您搜索......搜索
爲:CARYS
其中是$字段定義(從SQL查詢)? – 2013-03-08 07:46:47
請快速搜索您收到的錯誤消息,您將得到足夠多的結果,指出您至少在正確的方向調試問題。 – deceze 2013-03-08 08:00:22
生成的SQL語句是什麼? – Raptor 2013-03-08 08:11:10