从SQL数据库中搜索和显示结果

时间:2022-09-10 19:55:10

I have an MySQL database and I need to search for either the transaction number (and it shows me my name, email and item_name) or search for my email address AND name AND date of purchase which will then give me my transaction number and item_name - I don't want anything to come up unless email, name and date of purchase are all correct.

我有一个MySQL数据库,我需要搜索交易号码(它显示我的姓名,电子邮件和item_name)或搜索我的电子邮件地址和名称和购买日期,然后我会给我交易号和item_name - 除非电子邮件,姓名和购买日期都正确,否则我不希望出现任何问题。

Fields in my database are:

我的数据库中的字段是:

iname
iemail
itransaction_id
item_name

Could someone please help.... this is what i currently have....

请有人帮忙....这就是我现在拥有的......

<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>

saved as findme.html

保存为findme.html

next:

下一个:

<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>

Which is saved as findme.php

哪个保存为findme.php

This is the error im currently getting:

这是我目前得到的错误:

Search Results:

搜索结果:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php on line 31

警告:mysql_fetch_array():提供的参数不是第31行/hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php中的有效MySQL结果资源

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php on line 43 Sorry, but we can not find an entry to match your query...

警告:mysql_num_rows():提供的参数不是第43行/hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php中的有效MySQL结果资源抱歉,我们找不到符合您查询的条目...

Searched For: CARYS

搜索:CARYS

3 个解决方案

#1


2  

SELECT * FROM ibn_table WHERE itransaction_id LIKE '%$find%'
Note the space between LIKE and '%$find%'

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

#2


0  

i have tri for you just check it..

我有三个你只是检查..

            <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>

#3


0  

Just as a follow-up, I had this same error (php scripts displaying as text) and the way I fixed it is I checked the web address I was using for my webpages (this assumes I was running my WAMP from my local computer).

就像后续一样,我有同样的错误(php脚本显示为文本)和我修复它的方式是我检查了我用于我的网页的网址(这假设我从我的本地计算机运行我的WAMP) 。

You should access your pages through the 'localhost/somewebpage.html' format rather than the 'file:///C:/wamp/www/somewebpage.html' format. If you go to your www folder from the WAMP server menu in the sytem tray and double click the html page you are trying to run, it will open up to the 'file:///C:/wamp/www/somewebpage.html' format.

您应该通过“localhost / somewebpage.html”格式而不是“file:/// C:/wamp/www/somewebpage.html”格式访问您的网页。如果从系统托盘中的WAMP服务器菜单转到www文件夹,然后双击您尝试运行的html页面,它将打开到'file:/// C:/wamp/www/somewebpage.html '格式。

As is obvious, the way around this is to open a browser and manually type "localhost/somewebpage.html" to view the webapge. Running it that way forces it to run through your Apache server which can process the php. Running it the other way forces the page to run entirely from the browser and your web browser is not a webserver so it handles the php script as plain text and displays it on your page.

很明显,解决这个问题的方法是打开浏览器并手动输入“localhost / somewebpage.html”来查看webapge。以这种方式运行它会强制它运行可以处理php的Apache服务器。以另一种方式运行它会强制页面完全从浏览器运行,并且您的Web浏览器不是Web服务器,因此它将php脚本作为纯文本处理并显示在您的页面上。

#1


2  

SELECT * FROM ibn_table WHERE itransaction_id LIKE '%$find%'
Note the space between LIKE and '%$find%'

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

#2


0  

i have tri for you just check it..

我有三个你只是检查..

            <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>

#3


0  

Just as a follow-up, I had this same error (php scripts displaying as text) and the way I fixed it is I checked the web address I was using for my webpages (this assumes I was running my WAMP from my local computer).

就像后续一样,我有同样的错误(php脚本显示为文本)和我修复它的方式是我检查了我用于我的网页的网址(这假设我从我的本地计算机运行我的WAMP) 。

You should access your pages through the 'localhost/somewebpage.html' format rather than the 'file:///C:/wamp/www/somewebpage.html' format. If you go to your www folder from the WAMP server menu in the sytem tray and double click the html page you are trying to run, it will open up to the 'file:///C:/wamp/www/somewebpage.html' format.

您应该通过“localhost / somewebpage.html”格式而不是“file:/// C:/wamp/www/somewebpage.html”格式访问您的网页。如果从系统托盘中的WAMP服务器菜单转到www文件夹,然后双击您尝试运行的html页面,它将打开到'file:/// C:/wamp/www/somewebpage.html '格式。

As is obvious, the way around this is to open a browser and manually type "localhost/somewebpage.html" to view the webapge. Running it that way forces it to run through your Apache server which can process the php. Running it the other way forces the page to run entirely from the browser and your web browser is not a webserver so it handles the php script as plain text and displays it on your page.

很明显,解决这个问题的方法是打开浏览器并手动输入“localhost / somewebpage.html”来查看webapge。以这种方式运行它会强制它运行可以处理php的Apache服务器。以另一种方式运行它会强制页面完全从浏览器运行,并且您的Web浏览器不是Web服务器,因此它将php脚本作为纯文本处理并显示在您的页面上。