PHP/PDO/MariaDB: Trying to pull a single value based on a session "user_id" and print the result

26 views Asked by At

I'm a noob at PHP and am attempting to run a query using PDO to pull a single value based on a "user_id" value that is a part of the login session. There is a user_type column that indicates user or admin. I can't get the $user_type to echo on the page but I can get the $user_id to echo.

It doesn't error out. I'm pretty stumped on it and am hoping for some help.

    $user_query = "SELECT user_type FROM users WHERE 'user_id' = '".$user_id."'";
    $stmt = $pdo->query($user_query);

    if ($stmt === false) {
        die("Error executing the query.");
    }

    else $user_type = $stmt->fetchColumn();
    echo $user_type; echo $user_id;
0

There are 0 answers