我必须检查电子邮件ID是否存在。我知道这个问题是问服务器时间,我也检查谷歌但仍然得到问题。我尝试了一些代码,但我不知道我错在哪里。你能帮帮我吗?
<input type="email" name="email" id="email">
<div id="status"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#email").keyup(function() {
var name = $('#email').val();
if(name=="")
{
$("#status").html("");
}
else
{
$.ajax({
type: "POST",
url: "process.php",
data: "email="+ name ,
success: function(html){
$("#status").html(html);
}
});
return false;
}
});
});
</script>
Process.php
/*Checking email available or not*/
if(isset($_POST['email']))
{
$chk_email=$_POST['email'];
$sql=" SELECT Email FROM request WHERE Email='$chk_email'";
$result_email = mysqli_fetch_assoc($conn->query($sql));
if($result_email==0){
echo "<span style='color:green;'>Available</span>";
}
else
{
echo "<span style='color:red;'>Already register</span>";
}
}
答案 0 :(得分:1)
你需要发布这样的数据:
$.ajax({
type: "POST",
url: "process.php",
data: {email: name},//<--- Look here
success: function(html){
$("#status").html(html);
}
});
哦,在你的php代码中使用mysqli_escape_string
来逃避字符串以避免mysql注入。