这是我的jquery代码:
$(document).ready(function(){
$("#reg").validate({
debug: false,
rules: {
username: {
required: true,
remote: "username_check.php"
.............
这是我的PHP代码:
if(isset($_POST['username'])){
$username = ($_POST['username']);
if (!empty($username)) {
$username_query=mysql_query("SELECT COUNT(`user_name`) FROM `std_info` WHERE `user_name`='$username'");
$username_result=mysql_result($username_query, 0);
if ($username_result == 0) {
//echo 'AVAILABLE!';
$check= false;
}
else if ($username_result == 1) {
//echo 'ALREADY TAKEN.';
$check= true;
}
echo json_encode($check);
}}
但我无法回报价值。 有人可以帮忙吗?
答案 0 :(得分:0)
只需更改您的代码
if (!empty($username)) {
$username_query=mysql_query("SELECT COUNT(`user_name`) As count FROM `std_info` WHERE `user_name`='$username'");
$username_result=mysql_result($username_query, 0);
$row=mysql_fetch_assoc($username_result);
$cnt=$row['count'];
if ($cnt==1) {
$check= true;
}
else {
$check= false;
}
echo json_encode($check);