When php modifies this data entry, it prompts that the user name already exists. php jquery data ajax
No problem when adding
When you modify the data, the system prompts "the user name already exists"
Reply to discussion (solution)
It is too difficult to view images. paste the text code.
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"; // The user name already exists }}
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, "user name: already exists"] ;}else {return [true, ""] ;}}
It is too difficult to view images. paste the text code. OK. please advise.
$ SQL = "SELECT * FROM". $ tbName. "WHERE". $ where;
After
Echo $ SQL;
Check whether the SQL string has any problems.
Of course
Success: function (data ){
IsExistName = data
}
To be modified
Success: function (data ){
IsExistName = data
Alert (data );
}
$ SQL = "SELECT * FROM". $ tbName. "WHERE". $ where;
After
Echo $ SQL;
Check whether the SQL string has any problems.
Of course
Success: function (data ){
IsExistName = data
}
To be modified
Success: function (data ){
IsExistName = data
Alert (data );
}
When modified
Run $ SQL = "SELECT * FROM". $ tbName. "WHERE". $ where;
There is a piece of data
If my code is used, 1 is returned (this user name is included)
Therefore, the system prompts "the user name already exists"
How can this problem be solved (there is a problem only when there is modification, no problem is added)
Upload the ID of the current modified record
$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
This user can talk about "modification"
So you need to separate insertion and modification.
Upload the ID of the current modified record
$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
+ 1
Upload the ID of the current modified record
$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
Thanks. you have to separate insertion and modification.