Php prompts that the user name already exists when modifying this data

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.