I do not understand why the following code do not work as it should.

$result= query("SELECT * FROM users WHERE username = ?", $_POST["username"]);

if($result === true)
    apologize("Username already exists");

Instead, if I use only two equal signs instead of three i.e

if ($result == true)

the code seems to work. Can someone please elaborate on this? Cheers

1 Answer 1


The if ($row === false) syntax is used for queries that do not return rows, like an UPDATE or INSERT query. Review the Walkthrough -> login section of the pset7 instructions (pages 16-17). This statement is key:

an empty array is == to false because of implicit casting

Since you are testing for a non-empty array, you need to use if ($row == true) syntax. You could also use if (!empty($row)). This may make your intention clearer.

  • Thanks a lot!!!
    – James C
    Dec 1, 2015 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .