Blake Connally Blake Connally - 5 months ago 16
MySQL Question

PHP and MySQL query set to session

I cannot figure out why this isn't working. Every time I run it, it automatically assigns to verified. Any ideas?

$verify = "SELECT verification_status
FROM users
WHERE username = '$username' ";
$result2 = $conn->query($verify);

if ($result2 == 'verified') {
$_SESSION['verifiedstatus'] = 'verified';
} elseif ($result2 == 'pending') {
$_SESSION['verifiedstatus'] = 'pending';
} elseif ($result2 == 'unverified') {
$_SESSION['verifiedstatus'] = 'unverified';


@Fred-ii- Please post your responses a an answer, they helped me get it fixed. It is working properly now after making some adjustments to iterate the query. Thank you. – Blake Connally

As OP's request.

You haven't iterated over the query.

A loop is required to do this, such as a while loop and checking if a row equals something.

You also seem to be learning (MySQL), therefore I suggest that you read up on SQL injection:

Since you may be querying from possible user input.