rx0 Posted December 2, 2009 Share Posted December 2, 2009 Seems to be outputting an error, I have no other problems with my querys formatted like this, anyone got an idea? Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\includes\config.php on line 163 $connection = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db($db_name, $connection); function Search($x) { // Search Ringtones Functions $s = $_POST['s']; $q = "SELECT * FROM ringtones WHERE artist = ".$s.""; $numresults=mysql_query($q); $numrows=mysql_num_rows($numresults); // This is line 163 $result = mysql_query($q) or die("Couldn't execute query"); if ($numrows == 0) { echo "No Results Found ):"; } while ($row = mysql_fetch_array($result)) { $id = $row["id"]; $artist = $row["artist"]; $name = $row["name"]; $views = $row["views"]; $rating = $row["rating"]; echo "<tr><td><a href='view.php?ringtone=".$artist."-".$name."'>".$artist."</a></td><td><a href='view.php?ringtone=".$artist."-".$name."'>".$name."</a></td><td>".$views."</td><td>".$rating."</td></tr>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/183724-mysql_num_rows-error/ Share on other sites More sharing options...
Mchl Posted December 2, 2009 Share Posted December 2, 2009 Most likely mysql_query() in the line above returns false (it fails). Try like this: $result=mysql_query($q) or die(mysql_error().": $q"); $numrows=mysql_num_rows($result); I'm gueassing you should change your query to: $s = mysql_real_escape_string($_POST['s']); $q = "SELECT * FROM ringtones WHERE artist = '$s'"; Quote Link to comment https://forums.phpfreaks.com/topic/183724-mysql_num_rows-error/#findComment-969703 Share on other sites More sharing options...
rx0 Posted December 2, 2009 Author Share Posted December 2, 2009 Hmm seems to have removed the sql error issue but now I'm faced with SQL errors: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Spears' at line 1: SELECT * FROM ringtones WHERE artist = Britney Spears Unknown column 'Brokencyde' in 'where clause': SELECT * FROM ringtones WHERE artist = Brokencyde Quote Link to comment https://forums.phpfreaks.com/topic/183724-mysql_num_rows-error/#findComment-969705 Share on other sites More sharing options...
rx0 Posted December 2, 2009 Author Share Posted December 2, 2009 Never mind it's fixed, thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/183724-mysql_num_rows-error/#findComment-969708 Share on other sites More sharing options...
Maq Posted December 2, 2009 Share Posted December 2, 2009 Never mind it's fixed, thanks for your help! So to clarify as to what solved the problem, you needed single quotes (as Mchl suggested) around the value in the WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/183724-mysql_num_rows-error/#findComment-969740 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.