doufei5315 2015-03-23 05:26
浏览 85
已采纳

在登录表单上显示错误消息

I have created a login page for a website. the code of the form and its backend code is on the same page

View of db table is

id        email         password   status   block
1   vendor@gmail.com     vendor    vendor   active
2    ABC@gmail.com        ABC      vendor   inactive

Code for form is

        $myemail = mysqli_real_escape_string($con, $_POST['email']);
        $mypassword = mysqli_real_escape_string($con, $_POST['password']);
        $sql = "SELECT id FROM register WHERE email='$myemail' and password='$mypassword' and status='vendor' and block='inactive'";
        $result = mysqli_query($con, $sql);

        if (mysqli_num_rows($result) > 0)
            {
                while($row = mysqli_fetch_assoc($result)) 
                    {
                        $_SESSION['login_user']= $row["email"];
                        header("location: vendorpanel.php");
                    }
            }

        else 
            {
                $error="Your Login Name or Password is invalid";
            }
    }
?>

<form class="login-form" action="" method="POST">
    <h1>Login Form</h1>
    <div>
        <input type="text" placeholder="email" required="" id="email" name="email" />
    </div>
    <div>
        <input type="password" placeholder="Password" required="" id="password" name="password"/>
    </div>
    <div>
        <input type="submit" value="Log in" name="submit" />
        <!--<a href="#">Lost your password?</a>
        <a href="#">Register</a>-->
    </div>
</form>

The login code works fine, but I would like to display 2 types of error as a pop up box.

1) the first error is if the password is wrong then it should display a password error
2) the second error is if the block parameter is active then the user should get a message that his account has been blocked

can anyone tell how I can do so.

  • 写回答

2条回答 默认 最新

  • dongzhi9906 2015-03-23 05:36
    关注

    repace in your php code,

     <?php 
    if($_SERVER["REQUEST_METHOD"] == "POST")
        {
     $isblock = false;
     $wrong_user_pwd = false;
            $sql = "SELECT id,block FROM register WHERE email='$myemail' and password='$mypassword' and status='vendor'";
            $result = mysqli_query($con, $sql);
    
            if (mysqli_num_rows($result) > 0)
                {
                    while($row = mysqli_fetch_assoc($result)) 
                        {
                            $_SESSION['login_user']= $row["email"];
                            if($row['block'] == 'active')
                            $isblock = true;
                            header("location: vendorpanel.php");
                        }
                }
    
            else 
                {
                    $wrong_user_pwd= true;
                }
        }
    
       if($wrong_user_pwd) 
           echo "Your Login Name or Password is invalid";
      if($isblock)    
         echo "User Blocked";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?