0

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?

0

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

happens to us all, happy coding :)

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.