我有一个电子邮件输入字段。我需要检查输入电子邮件是否已存在于数据库中。我已经为它编写了以下代码。
HTML:
<script type="text/javascript" src="emailcheck.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<tr><td></td><td><input type="text" name="email" value="" placeholder="Your Email Address" id="email" required ><img id="tick" src="tick.png" width="16" height="16"/>
<img id="cross" src="cross.png" width="16" height="16"/></td></tr>
jquery就在这里:
$(document).ready(function(){
$('#email').keyup(email_check);
});
function email_check(){
var email = $('#email').val();
if(email == "" || email.length < 4){
$('#email').css('border', '3px #CCC solid');
$('#tick').hide();
}else{
jQuery.ajax({
type: "POST",
url: "check.php",
data: 'email='+ email,
cache: false,
success: function(response){
if(response == 1){
$('#email').css('border', '3px #C33 solid');
$('#tick').hide();
$('#cross').fadeIn();
}else{
$('#email').css('border', '3px #090 solid');
$('#cross').hide();
$('#tick').fadeIn();
}
}
});
}
}
文件check.php在这里:
<?php
mysql_connect("localhost","root","");
mysql_select_db("ignite");
$email = strtolower($_POST['email']);
$email = mysql_real_escape_string($email);
$query = "SELECT * FROM discover_science WHERE email = '$email' LIMIT 1";
$result = mysql_query($query);
$num = mysql_num_rows($result);
echo $num;
?>
输入电子邮件地址时,代码无响应。问题出在哪儿。请帮帮我。