I am trying to determine whether an email is aready in my database or not. For this purpose I write this piece of code:
$query_checkmail = "SELECT COUNT(*) FROM user WHERE email = ?;";
if($stmt = mysqli_prepare($connection, $query_checkmail))
mysqli_stmt_bind_param($stmt, "s", $_POST["email"]);
$result = mysqli_stmt_execute($stmt);
SELECT id FROM user WHERE email = ?;";
The count itself doesn't return a boolean true or false, you're checking against a variable assigned from
mysqli_stmt_execute(), which returns a boolean. This has nothing to do with the results of the query. If you'll read the documentation on this function, specifically the return values of
mysqli_stmt_execute(), you'll see that they are either
false, so there is no surprise that a
var_dump() of that would return a boolean.
If you want the actual count, you have to use
mysqli_stmt_fetch() to get the results of the count. This would produce the correct results. The manuals of this would show examples of that if you are unsure how to use these functions.
As for the
NULL, it's because you're passing a boolean into the
mysqli_fetch_all() function, which expects a mysqli_result, while you're giving it a boolean from the above-mentioned reasons.