我正在尝试创建一个注册表单,以使用 AJAX 通过电子邮件检查用户是否已经在系统中。我似乎无法让我的 php 文件运行,但我尝试了论坛中的各种项目。任何人都可以帮助我的代码
脚本如下。
<script>
function showUser() {
var useremail = $('#useremail').val();
var userpassword = $('#userpassword').val();
var userzip = $('#userzipcode').val();
var url = "/assets/php/userlogin/userdupcheck.php?e="+useremail+"&p="+userpassword+"&z="+userzip;
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
}
</script>
html表单是
<div id="registration" title="Register at TownCaddy.com">
<form name="register" id="register" onsubmit="showUser()">
<table>
<tr>
<td><input id="useremail" name="useremail" type="text" placeholder="Your Email" size="20" maxlength="45" /></td>
</tr>
<tr>
<td><input id="userpassword" name="userpassword" type="password" placeholder="Password" size="20" maxlength="32" /></td>
</tr>
<tr>
<td><input id="userzipcode" name="userzipcode" type="text" placeholder="Zip" size="5" maxlength="5" /></td>
</tr>
<tr>
<td colspan="4"><input name="submit" type="submit" value="Register" /></td>
</tr>
</table>
</form>
</div>
PHP文件userdupcheck.php代码如下
<?php
$e = $_GET['e'];
$p = $_GET['p'];
$z = $_GET['z'];
$query_dupUserCheck = "SELECT tblUser.userKey FROM tblUser WHERE tblUser.useremail = '".$e."'";
$sqlsearch = mysql_query($query_dupUserCheck);
$resultcount = mysql_num_rows($sqlsearch);
if ($resultcount > 0) {
print '<script type="text/javascript">';
print 'alert("The email address '. $e.' is already registered")';
print '</script>';
} else {
require_once('register.php');
}
?>