2013-03-08 83 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脚本并将其显示在页面上。