grlayouts Posted January 26, 2011 Share Posted January 26, 2011 Hey guys, i'm sure this is simple i have a script that always brings back the same error and I beleive it's going to be the php version im on the code is function check_user( $u ) { $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`=$u"); list($total_rows) = mysql_fetch_array($res) or die (mysql_error()); if( $total_rows > 0 ) return true; else return false; } the error is Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bofs/public_html/thief/inc/userinc.php on line 10 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 '' at line 1 any idea's Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/ Share on other sites More sharing options...
grlayouts Posted January 26, 2011 Author Share Posted January 26, 2011 also sorry the query function query($q) { global $conn; $result = mysql_query($q, $conn); } return $result; Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1165384 Share on other sites More sharing options...
BlueSkyIS Posted January 26, 2011 Share Posted January 26, 2011 if there is an error in the query, i like everything to STOP and tell me what the problem is, along with the query that caused the error. $result = mysql_query($q, $conn) or die(mysql_error() . " IN $q"); Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1165487 Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 $res = query("SELECT . . . Oddly enough, I can't find any reference to the query function in the php manual. Perhaps that's the issue. Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1165499 Share on other sites More sharing options...
grlayouts Posted January 28, 2011 Author Share Posted January 28, 2011 tried that and the same error 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 '' at line 1 IN SELECT * FROM `usertable` WHERE `userid`= Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1166451 Share on other sites More sharing options...
cyberRobot Posted January 28, 2011 Share Posted January 28, 2011 Looking at the query: SELECT * FROM `usertable` WHERE `userid`= It looks like $u doesn't contain any data which causes the query to fail. If you echo $u before querying the database, does it show anything? ... function check_user( $u ) { echo "<div>User ID: $u</div>"; $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`=$u"); ... Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1166528 Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 Didn't see the query() function defined in the second post. Where are you getting the value you're passing to the the check_user() function? Have you echoed it to make sure the value is what you'd expect? Quote Link to comment https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/#findComment-1166585 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.