AsiaUnderworld Posted February 26, 2009 Share Posted February 26, 2009 I've moved my code to a new server, and ive now got these errors Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 42 Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 42 Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 57 Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 57 Warning cannot modify header information - headers already sent by (output started at /home/niccaman/public_html/checkuser.php:42) in home/niccaman/public_html/checkuser.php on line 24 Whats up with this? Here are the lines around 42: 37 global $con; 38 $q = "SELECT ID FROM userinfo WHERE username = '$user'"; 39 $result = mysql_query($q, $con); 40 $result = mysql_fetch_array($result) o die ('error: ' .mysql_error()); 41 $i = 0; 42 while ($i <= mysql_num_rows($result)) 43 { 44 $r = $r . $result[$i]; 45 $i++; 46 } 47 48 return $r; 49 } help would be great Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/ Share on other sites More sharing options...
pquery Posted February 26, 2009 Share Posted February 26, 2009 Is there any way for you to check the logs from your old server? You might have moved to a server that's displaying the warnings in the php.ini instead of logging them. If your page is still displaying with the warnings that I would look that the display_errors setting on the php.ini and then restart apache Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771479 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 Try this: 37 global $con; 38 $q = "SELECT ID FROM userinfo WHERE username = '".$user."' "; 39 $result = mysql_query($q, $con); 40 $result = mysql_fetch_array($result) or die ('error: ' .mysql_error()); 41 $i = 0; 42 while ($i <= mysql_num_rows($result)) 43 { 44 $r = $r . $result[$i]; 45 $i++; 46 } 47 48 return $r; 49 } Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771483 Share on other sites More sharing options...
Philip Posted February 26, 2009 Share Posted February 26, 2009 Change: $result = mysql_query($q, $con); to $result = mysql_query($q, $con) or die(mysql_error()); You should put the or die on the query, not the fetch. BTW - I believe your loop logic is incorrect. Fetch array will return 1 row at a time, what you're doing is calling the array keys -- which turns out to be different column for one row. Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771544 Share on other sites More sharing options...
Q695 Posted February 26, 2009 Share Posted February 26, 2009 Actually you count the number of rows by: $num_rows = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771581 Share on other sites More sharing options...
Philip Posted February 26, 2009 Share Posted February 26, 2009 Actually you count the number of rows by: $num_rows = mysql_num_rows($result); Correct, but when you call: $result = mysql_fetch_array($result); It'll return 1 row result, not a multi-dimension array of the results. Returns an array of strings that corresponds to the fetched row' date=' or FALSE if there are no more rows. [/quote'] @OP: I'm guessing this is what you are aiming for, which doesn't make sense unless you allow duplicate usernames. function someFunction($user) { global $con; $q = "SELECT `ID` FROM `userinfo` WHERE `username` = '$user'"; $result = mysql_query($q, $con) or die(mysql_error); $r = array(); while ($row = mysql_fetch_array($result)) { $r[] = $row['ID']; } return $r; } If you explain your goal a bit more, I can show a better example Quote Link to comment https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771589 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.