登录表单验证消息

问题描述 投票:0回答:1

每当我试图用不正确的信息我没有得到错误信息登录,它只是当我尝试用不正确的信息登录重置我的表单。我想我可能有冲突的代码的某个地方。是不是有什么错我的代码?或者,如果可能的是有没有其他办法根据我的代码来提供验证?

一切工作正常。我只是需要验证。

我的PHP:

<?php

session_start();
ob_start();

//Include the database connection file
include "database_connection.php";

//Check to see if the submit button has been clicked to process data
if(isset($_POST["submitted"]) && $_POST["submitted"] == "yes")
{
    //Variables Assignment
    $username = trim(strip_tags($_POST['username']));
    $user_password = trim(strip_tags($_POST['passwd']));


    $validate_user_information = mysql_query("select * from `signup_and_login_users_table` where `username` = '".mysql_real_escape_string($username)."' and `password` = '".mysql_real_escape_string($user_password)."'");

    //Validate against empty fields
    if($username == "" || $user_password == "")
    {
        $error = '<br><div class="info">Sorry, all fields are required to log into your account. Thanks.</div><br>';
    }
    elseif(mysql_num_rows($validate_user_information) == 1) //Check if the information of the user are valid or not
    {
        //The submitted info of the user are valid therefore, grant the user access to the system by creating a valid session for this user and redirect this user to the welcome page
        $get_user_information = mysql_fetch_array($validate_user_information);
        $_SESSION["VALID_USER_ID"] = $username;
        $_SESSION["USER_FULLNAME"] = strip_tags($get_user_information["fullname"]);
        header("location: home.php");
    }
    else
    {
        //The submitted info the user are invalid therefore, display an error message on the screen to the user
        $error = '<br><div class="info">Sorry, you have provided incorrect information. Please enter correct user information to proceed. Thanks.</div><br>';
    }

}
?>

我的表格:

<div class="login">
    <font color="black" size="5"><p>Employee Login</p></font>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="text" name="username" placeholder="Username" required="required" />
        <input type="password" name="passwd" placeholder="Password" required="required" />
        <input type="hidden" name="submitted" id="submitted" value="yes">
        <button type="submit" name="submit" class="btn btn-primary btn-block btn-large">Login</button>
        <p></p>
        <a href="index.php"><img src="img/homebutton.png" height="35px" width="35px">
    </form>
</div>
php html forms validation login
1个回答
1
投票

首先使用mysqli功能不mysql,因为它们现在已过时。

其次,你没有得到错误信息的原因是因为你还没有打印错误消息。您应该添加echo $error;你定义你的error变量之后

© www.soinside.com 2019 - 2024. All rights reserved.