Home > Backend Development > PHP Tutorial > php修改本条数据时提示用户名已存在

php修改本条数据时提示用户名已存在

WBOY
Release: 2016-06-23 14:22:55
Original
1076 people have browsed it

php jquery 数据 ajax



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

回复讨论(解决方案)

看图片太费劲,还是贴文本代码出来吧。

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;	}
Copy after login
function IsExistUser($userName) {		$where = "name = '" . $userName . "'";		$clsSql = new DB_Support_jqGrid();		if ($userName != null)			$Num = $clsSql -> doSelectNums($this -> tbName, $where);		return $Num;	}
Copy after login
function IsExistUserName() {	$userName = $_POST["name"];	$clsSql = new AdminUser();	$result = $clsSql -> IsExistUser($userName);	if ($result == 0) {		echo "1";	} else {		echo "-9";//用户名已存在	}}
Copy after login
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, ""];					}				}
Copy after login

看图片太费劲,还是贴文本代码出来吧。 OK了 求指点

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

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

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

echo $sql;
看看 sql 串有无问题
当然
success : function(data) {
IsExistName = data
}
要改作
success : function(data) {
IsExistName = data
alert(data);
}
修改的时候
执行$sql = "SELECT * FROM " . $tbName . " WHERE " . $where;
有一条数据
如我代码 则返回 1(说明有这个用户名)
所以 修改时会提示 “用户名已存在”
该怎么解决 (只有修改时有问题 ,添加无问题)

把当前修改这条记录的ID传进去

$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
Copy after login
Copy after login
Copy after login

有这个用户才谈得上“修改”
所以你需要把插入和修改分开处理

把当前修改这条记录的ID传进去

$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
Copy after login
Copy after login
Copy after login
+1

把当前修改这条记录的ID传进去

$sql = "SELECT * FROM " . $tbName . " WHERE name='".$username."' and id<>".$id ;
Copy after login
Copy after login
Copy after login

这个可以 谢谢了 就是得把插入和修改分开处理

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template