添加时没问题
修改数据时 提示“用户名已存在”phpjquery数据ajax

解决方案 »

  1.   

    function doSelectNums($tbName, $where) {
    $sql = "SELECT * FROM " . $tbName . " WHERE " . $where;
    $result = mysql_query($sql) or die(mysql_error());
    $num = mysql_num_rows($result);
    return $num;
    }function IsExistUser($userName) {
    $where = "name = '" . $userName . "'"; $clsSql = new DB_Support_jqGrid();
    if ($userName != null)
    $Num = $clsSql -> doSelectNums($this -> tbName, $where);
    return $Num;
    }function IsExistUserName() {
    $userName = $_POST["name"]; $clsSql = new AdminUser();
    $result = $clsSql -> IsExistUser($userName);
    if ($result == 0) {
    echo "1";
    } else {
    echo "-9";//用户名已存在
    }
    }function isExistName(value, colname) {
    var IsExistName = null;
    $.ajax({
    type : "POST",
    url : "../php/Interface.php",
    data : {
    Index : "IsExistUserName",
    name : value
    },
    async : false,
    success : function(data) {
    IsExistName = data
    }
    });
    if (IsExistName == "-9") {
    return [false, "用户名: 已存在"];
    } else {
    return [true, ""];
    }
    }
      

  2.   

    $sql = "SELECT * FROM " . $tbName . " WHERE " . $where;

    echo $sql;
    看看 sql 串有无问题
    当然
                            success : function(data) {
                                IsExistName = data
                            }
    要改作
                            success : function(data) {
                                IsExistName = data
                                alert(data);
                            }
      

  3.   

    修改的时候
    执行$sql = "SELECT * FROM " . $tbName . " WHERE " . $where;
    有一条数据
    如我代码 则返回 1(说明有这个用户名)
    所以 修改时会提示 “用户名已存在”

    该怎么解决(只有修改时有问题 ,添加无问题)
      

  4.   

    把当前修改这条记录的ID传进去$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;