Jump to content

Recommended Posts

 

HI

I have following code for search my recipe database. Once I input search word (existing in database)

is displaying 0 results.

and error:

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in .... on line 217

 

 

My code:

$PHP_SELF = $_SERVER['HTTP_REFERER'];
$search=$_POST["search"];

$minchar = 2;
if (strlen($search) < $minchar)
{
	echo "Search must be longer than 2 characters.
} 
else 
{
    $result1 = mysql_query("SELECT * FROM recipe WHERE name LIKE '%$search%' 
    OR desc LIKE '%$search%'");

    $numrows1=mysql_num_rows($result1); // line 217
    if ($numrows1 == 0)
  	    {
		echo "<p>Sorry, your search returned 0 results</p>
  	    }
    else 
    { 
        while($row=mysql_fetch_array($result1))
        {	
       	        include "display_recipe.php";
        }
    }
}

 

I'm using similar code in another application and it works as it should be.

 

 

If some one can help me to find solution for this problem... please

 

Thanks a lot in advance...

Nita

 

Link to comment
https://forums.phpfreaks.com/topic/52103-solved-mysql-search-problem/
Share on other sites

change

<?php
$result1 = mysql_query("SELECT * FROM recipe WHERE name LIKE '%$search%' 
    OR desc LIKE '%$search%'");
?>

 

to

 

<?php
$result1 = mysql_query("SELECT * FROM recipe WHERE name LIKE '%$search%' 
    OR desc LIKE '%$search%'") or die(mysql_error());
?>

 

any errors ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.