在更新密码表单中,如果current password
与数据库中的密码不同,如何停止提交表单?
当前,我有一个表单,其中使用AJAX来检查文本框中的密码是否与数据库中的密码相同,如果不相同,它将显示一条消息,提示密码不正确,但是当我使用新密码提交表单时,密码将更新。
我希望如果文本框中的密码与数据库中的密码不同,则应该停止执行直到输入正确的密码为止。
FORM
<h5>Update Password</h5>
</div>
<div class="widget-content nopadding">
<form class="form-horizontal" method="post" action="#" name="password_validate" id="password_validate" novalidate="novalidate">
<div class="control-group">
<label class="control-label">Current Password</label>
<div class="controls">
<input type="password" name="current_pwd" id="current_pwd" />
<span id="chk_pwd"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">New Password</label>
<div class="controls">
<input type="password" name="new_pwd" id="new_pwd" />
</div>
</div>
<div class="control-group">
<label class="control-label">Confirm Password</label>
<div class="controls">
<input type="password" name="confirm_pwd" id="confirm_pwd" />
<span id="chk_confirm_pwd"></span>
</div>
</div>
<div class="form-actions">
<input type="submit" name="submit" value="Validate" class="btn btn-success">
</div>
</form>
JQUERY
$(document).ready(function(){
$('#new_pwd').click(function(){
var current_pwd=$('#current_pwd').val();
$.ajax({
type:'get',
url:'admin_profile_settings_back.php',
data:{current_pwd:current_pwd},
//dataType:"html",
success:function(resp){
$("#chk_pwd").html(resp).show().fadeOut(3000);
}
})
})
})
PHP Backend for AJAX
<?php
session_start();
include "../includes/config.php";
$current_pwd=$_GET['current_pwd'];
$aid=$_SESSION['aid'];
$r=$mysqli->query("SELECT * FROM admin WHERE aid='$aid' ");
$row=$r->fetch_assoc();
if($current_pwd==$row['password'])
{
echo "Password Is Correct";
}
else
{
echo "Password Is Incorrect";
}
答案 0 :(得分:1)
<?php
session_start();
include "../includes/config.php";
$current_pwd=$_GET['current_pwd'];
$aid=$_SESSION['aid'];
$current_pwd = $mysqli->real_escape_string($current_pwd);
$r=$mysqli->query("SELECT * FROM admin WHERE aid='$aid' and password='$current_pwd' ");
$row=$r->fetch_assoc();
if($current_pwd==$row['password'])
{
echo "Password Is Correct";
}
else
{
echo "Password Is Incorrect";
}