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 Link to comment https://forums.phpfreaks.com/topic/211644-checking-rows-in-database-not-working/ 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.'; } Link to comment https://forums.phpfreaks.com/topic/211644-checking-rows-in-database-not-working/#findComment-1103295 Share on other sites More sharing options...
Rifts Posted August 24, 2010 Author Share Posted August 24, 2010 that worked perfectly thanks Link to comment https://forums.phpfreaks.com/topic/211644-checking-rows-in-database-not-working/#findComment-1103368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.