hedgehog90 Posted May 11, 2010 Share Posted May 11, 2010 Hi, I check my error-logs on my website (www.gpstudios.com) and theres always lines and lines of this sort of stuff: [11-May-2010 06:43:21] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/news_comments.php on line 18 [11-May-2010 06:56:28] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13 [11-May-2010 06:56:29] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13 [11-May-2010 08:01:36] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123 [11-May-2010 08:01:36] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/specific_category.php on line 18 [11-May-2010 08:01:36] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123 [11-May-2010 08:01:40] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123 [11-May-2010 08:01:40] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/specific_category.php on line 18 [11-May-2010 08:01:40] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123 [11-May-2010 08:10:13] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13 [11-May-2010 08:17:44] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13 As you can see they happen in clumps, and not very often at all (in terms of errors/visitors). I'm pretty sure it's to do with my server just not connecting to the mysql database for small periods of time... In which case it's not fixable. Here is the php that I use that generate these errors: function get_category_name() { $args = func_get_args(); $catsql = mysql_query("select * from categories where id = $args[0]"); if(mysql_num_rows($catsql) > 0) { $result = mysql_fetch_array($catsql, MYSQL_ASSOC); return $result['category_name']; } } This is from functions.class.php. All the other errors I get are less frequent, but anyway, they are more or less exactly that (the mysql is written identically apart from different queries obviously) So, I'm guessing the answer is there's something wrong with my server, but in that case, do I just ignore these infrequent errors? Quote Link to comment https://forums.phpfreaks.com/topic/201365-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2010 Share Posted May 11, 2010 You are not validating the data being put into your query. Anytime $args[0] is empty or non-numeric, your query will fail, which will cause any code that expects $catsql to be a result resource to also fail and produce an error. You need to validate $args[0] to make sure it contains something and contains a number (or cast it as a number.) To troubleshoot this, you would need to find out what is actually being supplied in the function call to get_category_name, then either find and fix what is allowing the function to be called with a value that is not expected. Quote Link to comment https://forums.phpfreaks.com/topic/201365-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result/#findComment-1056484 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.