jQuery验证远程方法的使用情况,以检查用户名是否已经存在。我想要验证用户名是否存在于使用jQuery.Value的数据库中,下面是我到目前为止所得到的信息:jQuery: $("#signupForm").validate({
rules: {
username: {
required: true,
minlength: 3,
remote: "check-username.php"
}
},
messages: {
username:{
remote: "This username is already taken! Try another."
}
}
});php:<?php
require_once "./source/includes/data.php";header('Content-type: application/json');
$name = mysql_real_escape_string($_POST['username']);
$check_for_username = mysql_query("SELECT username FROM mmh_user_info WHERE username='$name'");
if (mysql_num_rows($check_for_username) > 0) {
$output = true;} else {
$output = false;}echo json_encode($output);?>这段代码总是显示一个错误,即使用户名不是。我正在使用jQueryMobile1.9.1提前谢谢。
2 回答
冉冉说
TA贡献1877条经验 获得超1个赞
<?php require_once "./source/includes/data.php";header('Content-type: application/json'); $request = $_REQUEST['username'];$query = mysql_query("SELECT * FROM mmh_user_info WHERE username ='$username'"); $result = mysql_num_rows($query);if ($result == 0){$valid = 'true';}else{$valid = 'false';}echo $valid;?>
添加回答
举报
0/150
提交
取消