Javascript 登记表在记录中插入“登记表”;对不起,电子邮件是“存在的”;阿莱尔特
在我的注册表单中,我想验证用户输入,并检查数据库中是否存在电子邮件,如果数据库中不存在电子邮件,php会插入值,但它仍会给我“对不起,电子邮件存在”警报,并且不会进入profile.html。插入select查询后,我应该添加吗Javascript 登记表在记录中插入“登记表”;对不起,电子邮件是“存在的”;阿莱尔特,javascript,php,mysql,sql,Javascript,Php,Mysql,Sql,在我的注册表单中,我想验证用户输入,并检查数据库中是否存在电子邮件,如果数据库中不存在电子邮件,php会插入值,但它仍会给我“对不起,电子邮件存在”警报,并且不会进入profile.html。插入select查询后,我应该添加吗 $('#sign-up').live('pageshow', function() { // Declare editMode : true when a user is logged in , false otherwise var
$('#sign-up').live('pageshow', function() {
// Declare editMode : true when a user is logged in , false otherwise
var editMode = globals.currentUser != null;
if(editMode) {
$("#txt-first-name").val(globals.currentUser.firstName);
$("#txt-last-name").val(globals.currentUser.lastName);
$("#txt-email").val(globals.currentUser.email);
}
$("#btn-submit").on("click", function(event){
event.preventDefault();
var firstName = $("#txt-first-name").val();
if(!firstName || firstName == "") {
alert("enter first name");
$("#txt-first-name").focus();
return;
}
var lastName = $("#txt-last-name").val();
if(!lastName || lastName == "") {
alert("enter last name");
$("#txt-last-name").focus();
return;
}
var email = $("#txt-email").val();
var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(!email || email == ""|| !filter.test(email)) {
alert("enter correct email");
$("#txt-email").focus();
return;
}
var password = $("#txt-password").val();
if(!editMode && (!password || password == "")) {
alert("enter password");
$("#txt-password").focus();
return;
}
if(password.indexOf(" ") > -1) {
alert("password must not have space");
$("#txt-password").focus();
return;
}
var passwordConfirm = $("#txt-password-confirm").val();
if(!editMode && (!passwordConfirm || passwordConfirm == "")) {
alert("confirm password");
$("#txt-password-confirm").focus();
return;
}
// Check if password and password confirmation are equal
if(passwordConfirm !== password) {
alert("passwords not equal to each other");
$("#txt-password-confirm").focus();
return;
}
var data = {
email: email,
password: password == "" ? "" : btoa(password),
firstName: firstName,
lastName: lastName,
id: (globals.currentUser != null ? globals.currentUser.userid : null)
};
$.getJSON(globals.serviceHost + (editMode ? "editprofile.php" : "register.php"), data,
// on success callback
function (result) {
console.log("result : ");
console.log(result);
if(editMode) {
globals.currentUser.firstName = firstName;
globals.currentUser.lastName = lastName;
globals.currentUser.email = email;
alert("information has been edited");
window.history.back();
}
if(!result.user || result.user == "data") {
alert("sorry,email is exist");
$("#txt-email").focus();
return;
}
globals.currentUser = result.user;
alert("register successfully ");
$.mobile.navigate("profile.html");
});
});
});
//php
此条件
if(!result.user || result.user == "data")
始终返回true,因为根据您的回答,该值始终为true
用户不存在:
echo '{"inserted":"true"}';
用户存在:
$data = "data";
echo '{"user":'. json_encode($data) .'}';
你的情况应该是
if(result.user == "data")
您的代码易受SQL注入攻击,您需要修复此问题。您的意思是什么?您好@RaomB,看起来原因是!result.user
,因为只要用户成功插入数据库,json中的用户数据就不会返回给您。另外,@Enstage至少是正确的。GET数组的来源未知。需要为此添加HTML。查看开发人员控制台,在查询中使用php的错误报告和错误检查,不仅仅是注入,而是明文密码。
if(result.user == "data")