0

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';
}

11
  • 1
    there are many syntax errors here. Not quoting values and assigning rather than comparing. It's also unknown if the session was started. Commented Sep 5, 2016 at 21:07
  • 2
    $result2 = 'verified' -> $result2 == 'verified' Commented Sep 5, 2016 at 21:08
  • 1
    Instead of a pile of if statements, why not either a switch or an in_array test? Commented Sep 5, 2016 at 21:24
  • 2
    @BlakeConnally Nothing wrong with learning. Just giving you a few things to look into so you can broaden your tool set. Commented Sep 5, 2016 at 21:25
  • 1
    @tadman Wow! That's amazing, just rearranged it using switch. So much more effective. Thank you. Commented Sep 5, 2016 at 21:30

1 Answer 1

3

@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.

Sign up to request clarification or add additional context in comments.

2 Comments

Correct, thank you. I did a while loop and it worked perfect. Thank you.
@BlakeConnally I made a slight edit to my answer about SQL injection. You may want to read up on that, cheers (You will need to reload it in order to see the addition).

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.