0

I have this php statement in my login script...

else if ($_POST['email'] === $details['email'] &&
         $_POST['password'] === $details['password'] &&
         is_null($details['logcount'])) {
    echo 'Account not active!';
}

In my mysql table the logcount by default is NULL, when a user activates their account the logcount turns to 0 then increments every time they login.

On my login script I am having trouble with PHP testing it to see if it is NULL or not. I have pulled all the users data via an associative array using PDO.

Thanks in advance.

8
  • 3
    Storing plain-text passwords in the database is bad. You should be hashing them at the very least. Commented Aug 22, 2011 at 5:18
  • 1
    you can set default to -1 and check if logcount < 0 Commented Aug 22, 2011 at 5:19
  • Good idea, thanks Haim, I am testing Phil, just trying to get the mechanics working first! thanks. Commented Aug 22, 2011 at 5:20
  • @carlgcoder What does var_dump($details['logcount']) display? I only ask as is_null() returns true for null and false for 0 and "0" so your code should work as expected. Commented Aug 22, 2011 at 5:22
  • Try doing a var_dump($details); to see what's actually in there. While your at it, do a var_dump($_POST) to make sure that everything is as expected. You can also break down each of the three comparisons to see which one is failing. Commented Aug 22, 2011 at 5:28

1 Answer 1

1

Try using the isset() function. If not, then you may have to tell PDO how to handle nulls for your db server. Look at the accepted solution here:

PHP PDO fetch null

and setattribute docs here:

http://php.net/manual/en/pdo.setattribute.php

Sign up to request clarification or add additional context in comments.

4 Comments

The problem lies somewhere else. is_null() is the right function to use for the purpose. If there's some way to tell PDO how to handle nulls, give an example of that.
@Doug See php.net/manual/en/pdo.setattribute.php however the default is to return nulls as NULL
Cool. Can you modify your answer with that info?
Ok, I edited this answer to be more descriptive. I think result from isset() vs is_null() depends on how PDO is handling nulls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.