1

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.

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

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

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

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

Searched For: CARYS

3
  • where is $field defined (from SQL query)? Commented Mar 8, 2013 at 7:46
  • Please do a quick search for the error messages you're getting, you'll get more than enough results that point you at least in the right direction for debugging the problem. Commented Mar 8, 2013 at 8:00
  • what is the resultant SQL statement ? Commented Mar 8, 2013 at 8:11

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that fixed the errors but it now says: Sorry, but we can not find an entry to match your query... any ideas?
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>

Comments

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

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.

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.