我使用用戶名和密碼創建了登錄模式表單。成功登錄將重定向到我的管理儀表板。當我嘗試登錄我的登錄模式窗體下方的不正確憑據時,是否有辦法將錯誤消息「用戶名和密碼不正確」?以模態登錄錯誤消息
我的模式形式:
<li class="active"> <a href="#" data-toggle="modal" data-target="#login-modal">Login</a></li>
<div class="modal fade" id="login-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="loginmodal-container">
<h1>Login</h1><br>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" name="submit" class="login loginmodal-submit" value="Login">
</form>
</div>
</div>
</div>
腳本:
<?php
require('db1.php');
session_start();
if (isset($_POST['username'])){
$username = stripslashes($_REQUEST['username']);
$username = mysqli_real_escape_string($con,$username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysqli_error());
$rows = mysqli_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
header("Location: view.php");
}else{
echo "<div class='login-modal'>Username or password is incorrect.<br/>Click here to <a href='index.php'>Login</a></div>";
}
}else{
?>
你可以寄支票作爲一個AJAX請求。你應該參數化你的查詢,而不是去掉斜槓,並使用更新的哈希算法。 – chris85
窗體和php是在同一個文件? – JYoThI
@JYoThI是的形式和PHP是在同一個文件 –