I am trying to figure out why this isn't working. What I am trying to do is return a value after the function is called. It is a login function which is supposed to check the database for the users status. That value being $userStatus. Depending on the status I'd like to return a value which would then trigger the error. However the script only fires off the first else if statement.
Here is the index page which calls the script
if(isset($_POST['btn-login'])) {
$uname = strip_tags($_POST['txt_uname_email']);
$umail = strip_tags($_POST['txt_uname_email']);
$upass = strip_tags($_POST['txt_password']);
if ($login->doLogin($uname,$umail,$upass)) {
$login->userLoginTime($uname);
$login->redirect('home.php');
} else if ($userStatus == 0) {
$error = "Your account is not active!";
} else if ($userStatus == "") {
$error = "You don't have an account, please sign up";
}
}
?>
Here is the class page where the function is housed.
public function doLogin($uname,$umail,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT
user_id, user_name, user_email, user_pass, Enabled
FROM users WHERE user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
$userStatus = $userRow['Enabled'];
if ($userStatus == 5) {
if ($stmt->rowCount() == 1) {
if (password_verify($upass, $userRow['user_pass'])) {
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
} else {
return false;
}
}
if ($userStatus == 0) {
return $userStatus;
}
if ($userStatus == "") {
return $userStatus;
}
}