在PHP中显示错误消息

时间:2017-07-08 13:10:05

标签: php html

我想向用户显示错误消息,如果他们输入的凭据不正确(不要返回与我的数据库中的任何内容匹配),例如在登录表单中。 最简单的方法是什么? 这就是我现在所拥有的 -

<?php
require 'includes/common.php';
?>

<!DOCTYPE html>
<!--
Login page of Lifestyle Store
-->
<html>
<head>
    <title>Log In</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>


    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!---- External css file index.css placed in the folder css is linked--> 
<link href="css/index.css" rel="stylesheet" type="text/css"/> 
</head>
<body>

    <?php
    include 'includes/header.php';
    ?>
    <div class="row login">
        <div class="col-xs-4"></div>
        <div class="col-xs-4">
    <div class="panel panel-primary">
        <div class="panel-body">
            <p class="text-warning">Login to make a purchase-</p>
            <form action="login_submit.php" method="POST">
                <div class="form-group">
                    <label for="email">E-mail:</label>
                    <input type="text" class="form-control" name="email" value="Email">
                </div>
                <div class="form-group">
                    <label for="password">Password:</label>
                    <input type="text" class="form-control" name="password" value="Password">
                </div>
            </form>
             <button class="btn btn-primary" type="submit" name="submit">Log-in</button>
        </div>
        <div class="panel-footer">Don't have an account? <a class="a2" href="signup.html">Register!</a></div>
    </div>
        </div>
        <div class="col-xs-4"></div>
    </div>

    <?php
    include 'includes/footer.php';
    ?>
</body>

1 个答案:

答案 0 :(得分:0)

如果您使用mysql在数据库中搜索匹配项,请使用以下内容

$email = $mysqli->escape_string($_POST['email']);
$password  = $mysqli->escape_string($_POST['password']):
$result = $mysqli->query("SELECT * FROM users WHERE email='$email' AND password='$password'");
//check whether the user exists and redirecting if not exists
if ($result-> num_rows == 0){
$_SESSION['messege']= "You have entered Either Wrong Username or Password ";
header("location: error.php");
}