nita Posted May 19, 2007 Share Posted May 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52103-solved-mysql-search-problem/ Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/52103-solved-mysql-search-problem/#findComment-256889 Share on other sites More sharing options...
nita Posted May 19, 2007 Author Share Posted May 19, 2007 it was about that "desc" is one of the reserved words in php, i renamed column to "description" and works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/52103-solved-mysql-search-problem/#findComment-256895 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 yeah noticed that but error check is always worth adding Quote Link to comment https://forums.phpfreaks.com/topic/52103-solved-mysql-search-problem/#findComment-256897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.