我的问题是我有两个对 php 的 ajax 调用以获取注册表单。首先是用户名可用性检查,它工作得非常好,其次是密码检查,它不起作用,数据库和所有三个文件肯定是连接的,但我找不到问题。如果有人知道,谢谢。
这是html:
<div id="registration_form">
<table>
<tr>
<td>Choose Username:</td>
<td><input type="text" id="username" autofocus="autofocus" /><span id="username_status"> </span></td>
</tr>
<tr>
<td>Choose Password:</td>
<td><input type="password" id="password" /> <span id="password_status"></span></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" id="confirmpassword" /> <span id="pconfirm_status"></span></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" id="email" /><span id="email_status"></span></td>
</tr>
<tr>
<td>Confirm Email:</td>
<td><input type="text" id="confirmemail" /><span id="econfirm_status"></span></td>
</tr>
<tr>
<td><input type="submit" value="Register" id="submit" /> </td>
</tr>
</table>
<div id="regform_reply"></div>
</div>
这是jQuery:
$('#password').keyup(function()
{
var password = $(this).val();
$('#password_status').text('Searching...');
if (password != '')
{
$.post('php/register.php', { password: password }, function(data)
{
$('#password_status').text(data);
});
}
else
{
$('#password_status').text('');
}
});
$('#username').keyup(function()
{
var username = $(this).val();
$('#username_status').text('Searching...');
if (username != '')
{
$.post('php/register.php', { username: username }, function(data)
{
$('#username_status').text(data);
});
}
else
{
$('#username_status').text('');
}
});
这是php:
<?php
include '../connect/userdb_connect.php';
if (isset($_POST['password']))
{
$password = mysql_real_escape_string($_POST['password']);
if (!empty($password))
{
if (strlen($password)>25)
{
echo 'Too long';
}
else if(strlen($password)<6)
{
echo 'Too short';
}
else
{
echo 'Fine';
}
}
}
if (isset($_POST['username']))
{
$username = mysql_real_escape_string($_POST['username']);
if (!empty($username))
{
$check = mysql_query("SELECT `user_name` FROM `userbase` WHERE `user_name` = '$username'");
$result = mysql_num_rows($check);
if ($result == 0 && strlen($username) <25)
{
echo 'Available';
}
else if($result == 1 && strlen($username) <25)
{
echo 'Already taken';
}
else
{
echo 'Too long';
}
}
}
?>