Rifts Posted August 24, 2010 Share Posted August 24, 2010 Hey I'm trying to check a row in my database to see if its empty but this isnt working $usercheck = mysql_query("SELECT pet FROM users where name='$user'"); $returned_rows = mysql_num_rows($usercheck); if ($returned_rows == 0){ // do stuff if no pet }else{ echo 'There was ' . $returned_rows . ' records found.'; } The problem is its not checking the row pet its just checking to see if anything exists my database has id name pet 1 joe <empty> its just seeing joe and echoing "there was 1 record found" instead of seeing that the row pet is empty. thanks for the help Quote Link to comment Share on other sites More sharing options...
Stooney Posted August 24, 2010 Share Posted August 24, 2010 You need to use strlen() on the result. $data=mysql_fetch_assoc($usercheck); if(strlen($data['pet'])==0){ //Pet field is empty } else{ //Pet field not empty echo 'There was ' . $returned_rows . ' records found.'; } Quote Link to comment Share on other sites More sharing options...
Rifts Posted August 24, 2010 Author Share Posted August 24, 2010 that worked perfectly thanks Quote Link to comment 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.