Reputation: 788
I am writing a basic PHP login system for a school project, I am currently trying to implement email activation. Here is a snippet of my code.
$query = "
SELECT
id,
username,
password,
salt,
email
useractivestatus
FROM users
WHERE
username = :username
";
// The parameter values
$parameters = array(
':username' => $_POST['username']
);
try
{
// Execute the query against the database
$stmt = $db->prepare($query);
$result = $stmt->execute($parameters);
}
catch(PDOException $err)
{
die("Failed to run query: " . $err->getMessage());
}
$row = $stmt->fetch();
if($row)
{
if($active != $row['useractivestatus'] );
{
die("Account has not been activated");
}
The problem is using var_dump$row['useractivestatus'] I can see it always returns the data from the email column, causing the query to always return false and trigger the die response. I can do var_dump$row['any other column'] and it returns the correct data. why is the it returning the email when querying the useractivestatus column?
Upvotes: 0
Views: 32
Reputation: 2877
You are missing a comma in your query, as such email is actually aliased as useractivestatus and trying to select from the email column would fail.
$query = "
SELECT
id,
username,
password,
salt,
email, -- this comma was missing
useractivestatus
FROM users
WHERE
username = :username
Upvotes: 2