winkhere Posted July 10, 2007 Share Posted July 10, 2007 When any of my users try to login it is giving this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myhouse/public_html/tradingspace/user_login.php on line 42 I went to this file and this is what the paragraph says: $query = "select id from PHPAUCTION_users where username='$username' and password='".md5($MD5_PREFIX.$password)."' and suspended=0"; $res = mysql_query($query); //print $query;; if(mysql_num_rows($res) > 0) { $PHPAUCTION_LOGGED_IN = mysql_result($res,0,"id"); $PHPAUCTION_LOGGED_IN_USERNAME = $HTTP_POST_VARS[username]; session_name($SESSION_NAME); Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/ Share on other sites More sharing options...
AndyB Posted July 10, 2007 Share Posted July 10, 2007 Change $res = mysql_query($query); to $res = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); Then you'll find out what the error is. You can probably resolve most of the trouble by carefully processing user input before creating the query. Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294046 Share on other sites More sharing options...
winkhere Posted July 10, 2007 Author Share Posted July 10, 2007 Ok, when I did that, this is what came up: Error: Unknown column 'username' in 'where clause' with query select id from PHPAUCTION_users where username='myhouse' and password='645036f7dc456ff666d194daf21be791' and suspended=0 Not sure how to fix that error either... Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294049 Share on other sites More sharing options...
AndyB Posted July 10, 2007 Share Posted July 10, 2007 Error: Unknown column 'username' That's pretty specific. The database table you're looking in does not have a column named username. Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294050 Share on other sites More sharing options...
winkhere Posted July 10, 2007 Author Share Posted July 10, 2007 I had a brainfart...lol. I went into the PHPAdmin and the column was titled "nick", so I changed it to "username" and now it works. Do you foresee any issues I may have with this fix? I figured it was more standard than changing the other to nick... Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294051 Share on other sites More sharing options...
winkhere Posted July 10, 2007 Author Share Posted July 10, 2007 Ok, it let me login twice, and now it is giving me this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myhouse/public_html/tradingspace/login.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /home/myhouse/public_html/tradingspace/login.php:9) in /home/myhouse/public_html/tradingspace/login.php on line 18 There is nothing on line 9 or 18... Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294085 Share on other sites More sharing options...
AndyB Posted July 10, 2007 Share Posted July 10, 2007 The header error is a result of output to the browser (the earlier error message!). Fix the first error and the header error will disappear. The first error is caused because your database query has failed. If you add the error trap/display I suggested in my first reply .... tell us what you see. Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294188 Share on other sites More sharing options...
winkhere Posted July 11, 2007 Author Share Posted July 11, 2007 Ok... I was doing that and it wasn't working. Turns out, the first error was in users_login.php and the second error was in login.php... I was going to the same one. Thanks for the help! After eight hours in a row, everything looks the same! Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294867 Share on other sites More sharing options...
AndyB Posted July 11, 2007 Share Posted July 11, 2007 So error trapping has helped you resolve the problem? Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294881 Share on other sites More sharing options...
winkhere Posted July 11, 2007 Author Share Posted July 11, 2007 Yes! Very useful trick! Thank you Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294883 Share on other sites More sharing options...
AndyB Posted July 11, 2007 Share Posted July 11, 2007 Right. Use it for good not for evil Marking this one solved. Quote Link to comment https://forums.phpfreaks.com/topic/59194-solved-invalid-mysql-result-please-help/#findComment-294885 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.