I have the following function/method in my PHP code, where I want to check for some user content, based on either password or a token and email.
function login($email, $password, $token) {
    if (isset($email)) {
        if (isset($password) && strlen($password) > 0) {
            $stmt = $this->con->prepare("SELECT users.user_id, logins.email, logins.token, users.firstname, users.lastname, users.username
                                     FROM users
                                     INNER JOIN logins
                                         ON users.login_id = logins.login_id
                                     WHERE logins.email=? AND logins.password=?");
            $stmt->bind_param("ss", $email, $password);
        } elseif ($token && strlen($token) > 0) {
            $stmt = $this->con->prepare("SELECT users.user_id, logins.email, logins.token, users.firstname, users.lastname, users.username
                                     FROM users
                                     INNER JOIN logins
                                         ON users.login_id = logins.login_id
                                     WHERE logins.email=? AND logins.token=?");
            $stmt->bind_param("ss", $email, $token);
        } else {
            return $this->error_login_failure;
        }
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($rUserId, $rEmail, $rToken, $rFirstname, $rLastname, $rUsername);
        $stmt->fetch();
        if ($rUserId != null || strlen($rUserId) > 0) {
            $stmt->close();
            $newToken = $this->insertNewToken($email, $password, $rToken);
            if ($newToken == null) {
                return $this->error_login_failure;
            } else {
                $returnValues = array();
                $returnValues['userId'] = $rUserId;
                $returnValues['email'] = $rEmail;
                $returnValues['token'] = $rToken;
                $returnValues['firstname'] = $rFirstname;
                $returnValues['lastname'] = $rLastname;
                $returnValues['username'] = $rUsername;
                return $returnValues;
            }
        } else {
            $stmt->close();
            return $this->error_login_failure;
        }
    } else {
        return $this->error_login_failure;
    }
}
The problem is that, when I am passing the token (which is not null) I don't get anything returned. I have debugged it and found out that all input parameters are correct and the code reaches the elseif ($token && strlen($token) > 0) {. But when I try to get the returned data, nothing is returned. This is not happening if I pass in the password, only when it tries the second "if" with the token.
It also works if I take the second SQL query with the token as a parameter and run it in the terminal manually. I can't seem to find out what the problem is.
 
     
    