2017-07-08 119 views
-5

如果用戶輸入的憑證不正確(不會返回與我的數據庫中的任何內容匹配的內容),例如在登錄表單中,則向用戶顯示錯誤消息。 這樣做最簡單的方法是什麼? 這是我必須在之前NOW-在PHP中顯示錯誤消息

<?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> 

+0

所以在這裏你有什麼張貼您的問題迄今爲止嘗試過。 – lkdhruw

+0

@gp_sflover好的。未來將把所有這一切銘記在心! – Vaibhav

回答

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"); 
} 
+0

謝謝!然後,我只要在error.php中顯示$ _SESSION ['message']變量? – Vaibhav

+0

是的,用戶將被引導到error.php與會話信息,設置一個你可以使error.php在錯誤中回顯相關的** $ _ SESSION ['message'] **。 php – Shirantha

+0

好的。讓我試試這個! – Vaibhav