Rumah > Artikel > pembangunan bahagian belakang > php+ajax 更改密码的问题
别的错误都可以判读,新密码和重复密码不管是不是一致,都会开始倒计时发送验证码,不知道是什么原因?
这是js代码
/**
* tpl/change_pwd验证获取验证码
*/
function getCode_pwd(){
var oldpwd_val = $("#oldpwd").val();
var pwd_val = $("#pwd").val();
var re_pwd_val = $("#re_pwd").val();
if(oldpwd_val ==""){
$("#oldpwd_1").html("* 初始密码不能为空");
form_pwd.oldpwd.focus();
return false;
}else{
$("#oldpwd_1").html("");
}
if(pwd_val ==""){
$("#pwd_1").html("* 新密码不能为空");
form_pwd.pwd.focus();
return false;
}else{
$("#pwd_1").html("");
}
if(re_pwd_val ==""){
$("#re_pwd_1").html("* 重复密码不能为空");
form_pwd.re_pwd.focus();
return false;
}else{
$("#re_pwd_1").html("");
}
$.ajax({
type: "POST",
url: "../inc/changePwd.inc.php",
data:{
oldpwd : oldpwd_val,
pwd: pwd_val,
re_pwd : re_pwd_val
},
success: function(msg){
if(msg == "success"){
nowTime = 30;
$('#ck').attr('disabled',true);
$('#ck').attr('value', '查看手机(' + nowTime + ')');
setInterval("SetRemainTime()",1000);
}else{
if(msg == "error1"){
$("#oldpwd_1").html("* 原始密码输入错误");
return false;
}else{
$("#oldpwd_1").html("");
}
if(msg == "error2"){
$("#re_pwd_1").html("* 两次输入密码不一致");
return false;
}else{
$("#re_pwd_1").html("");
}
}
}
});
}
这是changePwd.inc.php代码
session_start();
include_once ("../conn/conn.php");
//include ("../information/check_interface.php");
$oldpwd = mysql_real_escape_string ($_POST['oldpwd']);
$pwd = mysql_real_escape_string ($_POST['pwd']);
$re_pwd = mysql_real_escape_string ($_POST['re_pwd']);
$user=$_SESSION['user'];
$result =mysql_query("SELECT * FROM tb_admin WHERE admin_user = '$user' AND admin_pwd = '$oldpwd'");
if(mysql_num_rows($result)!=0){
if(strtoupper($pwd) == strtoupper($re_pwd)){
$sql=mysql_query("SELECT admin_user,mobile_phone FROM tb_admin WHERE admin_user = '" . $user . "'");
while($row=mysql_fetch_array($sql)){
$mobile = $row['mobile_phone'];
$_SESSION['mobile'] = $mobile;
}
echo "success";
//echo postSendMessage();
}else{
echo "error2";
}
}else{
echo "error1";
}
mysql_close($conn);
?>
这是页面代码
你没有检查 新密码和重复密码 是否一致的代码
你没有检查 新密码和重复密码 是否一致的代码
太长,看的眼睛疼
个人觉得是你的if 判断写的有点凌乱了
if(mysql_num_rows($result)!=0){if(strtoupper($pwd) == strtoupper($re_pwd)){$sql=mysql_query("SELECT admin_user,mobile_phone FROM tb_admin WHERE admin_user = '" . $user . "'");while($row=mysql_fetch_array($sql)){ $mobile = $row['mobile_phone'];$_SESSION['mobile'] = $mobile;} echo "success";//echo postSendMessage();}else{echo "error2";}}else{echo "error1";}
太长,看的眼睛疼
个人觉得是你的if 判断写的有点凌乱了
if(mysql_num_rows($result)!=0){if(strtoupper($pwd) == strtoupper($re_pwd)){$sql=mysql_query("SELECT admin_user,mobile_phone FROM tb_admin WHERE admin_user = '" . $user . "'");while($row=mysql_fetch_array($sql)){ $mobile = $row['mobile_phone'];$_SESSION['mobile'] = $mobile;} echo "success";//echo postSendMessage();}else{echo "error2";}}else{echo "error1";}
html报错之后你没有停啊,就一直执行下去了啊。