如果其他语句不能在PHP中工作

时间:2016-06-19 16:11:40

标签: php

为一些课程工作登录,有些原因,即使符合标准,它也永远不会出现在其他地方,我已经使用变量打印来证明这一点,我们将非常感谢任何帮助。

if($_SESSION['username'] == $row['UserID'] and $password == $row['password'] and $row['loginAttempts'] < 3)  
        {
            //setting student session and redirecting
            if ($row["type"] == "0")
            {
                echo "student login";
                $_SESSION['student'] = 'true';
                $resetLoginAttempts;
                //header('Location: studenthome.php');
            }   
            //setting staff session and redirecting
            if ($row["type"] == "1") 
            {
                echo "Staff login";
                $_SESSION['staff'] = 'true';
                $resetLoginAttempts;
                //header('Location: staffhome.php');S
            }
        }
        //correct username but wrong password not over max login attempts
        elseif($_SESSION['username'] == $row['UserID'] and $password =! $row['password'] and $row['loginAttempts'] < 3)
        {
            echo "wrong pass";
            $incrementLoginAttemts;
        }
        //correct username, incorrect or correct password but user has used their 3 login attempts
        elseif($_SESSION['username'] == $row['UserID'] and $row['loginAttempts'] == 3)
        {
            echo "You've have been locked out, please contact the system admin";
        }
        elseif($_SESSION['username'] =! $row['UserID'] and $row['loginAttempts'] =! 3)
        {
            echo "wrong user name";
        }
    }

2 个答案:

答案 0 :(得分:1)

你颠倒了&#34;不等于&#34;并且收到语法错误,但没有检查错误。

所有

=!

应该是

!=

各种PHP版本中的错误演示:https://3v4l.org/8Xo7e

正确执行:https://3v4l.org/Xt2W5

答案 1 :(得分:0)

如果条件如下,则需要添加括号:

if(($_SESSION['username'] == $row['UserID']) and ($password == $row['password']) and ($row['loginAttempts'] < 3)) 希望这将是你的幸运

相关问题