$('#cemail').on('blur', function () {
var email = $(this).val();
var dataPosting = 'cemail=' + email;
console.log(email + ' ' + dataPosting);
$.ajax({
method: "post",
data: dataPosting,
url: 'check_dup_email.php',
success: function (data) {
console.log(data);
if (parseInt(data) === 1) {
$('#email_status').html('Email already used');
$('#cemail').focus();
console.log('Already Exists');
} else {
console.log('carry on');
$('#email_status').html('');
}
}
我尝试了我的表单的电子邮件验证...我想显示已存在的电子邮件,其中输入已在数据库中的电子邮件ID ...?请有人帮帮我吗?
答案 0 :(得分:0)
你应该更改ajax代码。你的比较错误的响应值 .just 更改ajax代码中的比较值。
$.ajax({
method: "post",
data: {
cemail : email
},
url: 'check_dup_email.php',
success: function (data) {
console.log(data);
if ((data) == "equal") {
$('#email_status').html('Email already used');
$('#cemail').focus();
console.log('Already Exists');
} else {
console.log('carry on');
$('#email_status').html('');
}
}
});
php代码:
<?php
include_once("init.php");
include_once'dbconfig.php';
//$email=filter_input(INPUT_POST,'cemail');
$query="select * from stock_sales where st_email='purender@gmail.com' ";
$result = mysqli_query($conn,$query);
$count=mysqli_num_rows($result);
if($count===1){ echo "equal"; } else{ echo "not equal"; }
&GT;