2013-03-08 155 views
1

我有一個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

+0

其中是$字段定義(從SQL查詢)? – 2013-03-08 07:46:47

+0

請快速搜索您收到的錯誤消息,您將得到足夠多的結果,指出您至少在正確的方向調試問題。 – deceze 2013-03-08 08:00:22

+0

生成的SQL語句是什麼? – Raptor 2013-03-08 08:11:10

回答

0

我有三對你只是檢查它..

  <html> 
      <head><title>Searching for a student...</title> 
      </head> 
      <body bgcolor=#ffffff> 

      <?php 
      include "config.php"; 
      echo "<h2>Search Results:</h2><p>"; 

      if(isset($_POST['search'])) 
      { 
      $find =$_POST['find']; 
      //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 


      // 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 ibntable WHERE name LIKE'%$find%'") 
      or die(mysql_error()); 

      //And we display the results 
      while($result = mysql_fetch_array($iname)) 
      { 
      echo "id :" .$result['fname']; 
      echo "<br> "; 
      echo "name :".$result['lname']; 
      echo "<br>"; 
      echo "name :".$result['middlename']; 
      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> 
2

SELECT * FROM ibn_table WHERE itransaction_id LIKE '%$find%'
注意LIKE和'%$ find%'之間的空格

+0

謝謝,修復了錯誤,但它現在說: 對不起,但我們無法找到與您的查詢相符的條目... 任何想法? – 2013-03-08 08:25:57

+0

我現在有工作 - 謝謝! – 2013-03-08 08:34:51

0

就像後續一樣,我有同樣的錯誤(php腳本顯示爲文本)和我修復它的方式是我檢查了我用於我的網址網頁(這個假設我是ru從我的本地計算機中指定我的WAMP)。

您應該通過'localhost/somewebpage.html'格式訪問您的頁面,而不是'file:/// C:/wamp/www/somewebpage.html'格式。如果您從系統托盤的WAMP服務器菜單轉到www文件夾,然後雙擊您要運行的html頁面,它將打開'file:/// C:/wamp/www/somewebpage.html '格式。

顯而易見,解決方法是打開瀏覽器並手動輸入「localhost/somewebpage.html」來查看網頁空間。以這種方式運行它將強制它通過可以處理php的Apache服務器運行。以另一種方式運行它可以強制頁面完全從瀏覽器運行,並且您的Web瀏覽器不是Web服務器,因此它以純文本的形式處理php腳本並將其顯示在頁面上。

相關問題