barrywood Posted September 25, 2007 Share Posted September 25, 2007 Hi, I'm a relative newbie to php but I've been programming in one language or another for 25+ years. What I'm running into is a situation where I contruct an SQL query, call mysql_query, and I'm not getting a FALSE return when it should not be finding a record. My query looks something like this: SELECT dist_IdNum, dist_Active, dist_Company FROM Distributors WHERE dist_Login = 'badlogin' The code snippet looks like this: $result = mysql_query( $query, $link ); if ($result) print 'found the login'; else print 'login not found'; It doesn't matter what I enter for the login, the call to mysql_query never gives me a FALSE return. Am I missing something really basic here? Quote Link to comment https://forums.phpfreaks.com/topic/70578-solved-mysql_query-never-returning-false/ Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 and I'm not getting a FALSE return when it should not be finding a record. If your query succeeds (record or not) you will get a result resource returned. Use mysql_num_rows. eg; <?php if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // display records. } else { // no record found. } } else { // query failed. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70578-solved-mysql_query-never-returning-false/#findComment-354636 Share on other sites More sharing options...
barrywood Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks Thorpe, that did the trick. As I suspected it was a newbie issue on my part. Quote Link to comment https://forums.phpfreaks.com/topic/70578-solved-mysql_query-never-returning-false/#findComment-354639 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.