Jump to content

Checking rows in database not working


Rifts

Recommended Posts

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

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.';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.