如果用户输入不正确的信息,则不会显示错误消息

杰克丹尼

如果使用时未输入正确的登录名组合,我将尝试在最后显示错误。但是,当我输入错误的密码或电子邮件时,不会显示错误消息。有什么建议么

 <?php
 include ("connect.php");

if (isset($_POST["user_login"]) && (isset($_POST["user_pass"]))){
    // formatting field via reg replace to ensure email and password only conisists of letters and numbers preg_replace('#[^A-Za-z0-9]#i','', 
    $login_user = $_POST["user_login"];
    $login_password = $_POST["user_pass"];


    // password is encryted in DB (MD5) therefore user inputted password will not match encryted password in DB - we have to assign new var
    $decrypted_password = md5($login_password);

// Query which finds user (if valid) from DB - Achieving authentication via username and password       

$user_query = mysqli_query($connect, "SELECT * FROM users WHERE email = '$login_user' AND password = '$decrypted_password' AND closed = 'no' LIMIT 1"); 

    $check_user = mysqli_num_rows($user_query); // checking to see if there is infact a user which those credentials in the DB
        if ($check_user==1){

        while ($row = mysqli_fetch_array($user_query)){
                $id = $row['user_id'];
                $user_type = $row['account'];
            }
            $_SESSION["user_login"] = $login_user;
            // check the user type and redirect according to it
            if($user_type == "Student"){
             $student_page = "profile_student.php";
             header( "Location:{$student_page}" );

           } elseif ($user_type == "Landlord"){
              $landlord_page = "landlord_profile.php";
              header( "Location:{$landlord_page}" );

           } elseif ($user_type == "Administrator"){
               $admin_page = "admin_profile.php";
               header( "Location:{$admin_page}" );

           }else {
               $refresh_page = "sign_up.php";
               header( "Location:{$refresh_page}" ); // refresh page

            echo "You have entered an incorrect email or password. Please try again.";

           }
           }
}

    ?>
努比

如果输入数据错误,您将重定向用户,只有在此之后,您才尝试回显消息,这不是工作原理。php_manual中阅读有关标头的信息可能最好的方法是在会话中存储错误消息,并在重定向后检查会话错误消息是否存在

else {
           $refresh_page = "sign_up.php";
            $_SESSION['error'] = "your error message"
           header( "Location:{$refresh_page}" ); // refresh page
       }

在sign_up.php文件中,检查会话中是否存在错误消息

if(isset($_SESSION["error"])){
     echo $_SESSION["error"];
      unset($_SESSION["error"]);
  }

也许您应该稍微纠正一下此代码))在显示应将其从会话中删除的消息后,使用unset cause';否则,例如,如果您失败了5次,它将显示5条消息))也请确保该会话开始session_start()希望对您有所帮助:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如果行数不正确,则放置用户无法继续的信息消息

如果密码或用户电子邮件格式不正确,则返回错误消息

在python中输入数据不正确时给出用户错误消息

如果网址不正确,如何使用.htaccess显示错误消息?

如果用户输入不正确,如何让问题循环

如果日期格式不正确,则返回错误消息

Java-错误消息显示不正确

如果路线Laravel不正确,则会显示错误页面

如果返回语句值,则不正确

用户输入的输出不正确

如果输入值只是空格,则不会出现错误消息

输入范围值显示不正确

输入范围滑块显示不正确

如果用户输入的长度小于最小长度,则显示错误消息

如果用户输入的数据不正确,应用程序必须重复提问

如果输入的值不正确,如何限制用户使用TextBox

如果输入的密码或用户名不正确,该如何循环

(Python)如果用户输入不正确,如何结束代码的基本方法?

如何设置引导程序验证器以在输入值不正确时不显示消息

如果我的日期格式在Rails中不正确,如何正确显示验证错误?

突出显示的代码错误不正确

SQL:错误显示不正确的行数

登录失败后,为什么Gmail不会显示用户名或密码不正确?

SnowflakeSQLException 错误代码:390100,消息:指定的用户名或密码不正确

聊天应用程序在用户发送消息且消息顺序不正确时随机显示消息

如果输入选项不正确,如何在bash中使此菜单错误

消息显示在错误的一侧并且大小/内容不正确(MessageKit)

DataGridView_RowHeaderMouseClick事件显示错误输入字符串的格式不正确

计算器显示错误:“输入字符串的格式不正确。”