报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin'

简介: 报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin'

在提交注册信息的时候报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'


原因:主键冲突 违反完整性约束 字段唯一索引


从上图可以看出,用户名和邮箱必须唯一,如果填入重复的用户名或者邮箱就会出错


解决方法:在控制器里面进行判断


data=input(′post.′);data = input('post.'); data=input(post.);uniquename = model('User')->get(['username'=>data\['username'\]\]);  if(sizeof(uniquename)){

this->error('该用户名已经注册,请重新填写~~~');  } uniqueemail = model('User')->get(['email'=>data\['email'\]\]);  if(sizeof(uniqueemail)){

$this->error('该邮箱已经注册,请重新填写~~~');

}


添加上面代码之后,如果填写了重复的用户名或者密码就会给用户相关提示~~~


对了,上面的代码是在TP5上写的。



目录
相关文章
|
6月前
Duplicate keys detected: '0'原因及解决方法
Duplicate keys detected: '0'原因及解决方法
|
6月前
|
关系型数据库 MySQL 数据库
Error: Table ‘bWAPP.users‘ doesn‘t exist
Error: Table ‘bWAPP.users‘ doesn‘t exist
|
数据库
Incorrect table definition; there can be only one auto column and it must be defined as a key
Incorrect table definition; there can be only one auto column and it must be defined as a key
185 0
Incorrect table definition; there can be only one auto column and it must be defined as a key
|
存储 关系型数据库 MySQL
ERROR 1215 (HY000): Cannot add foreign key constraint
ERROR 1215 (HY000): Cannot add foreign key constraint
ERROR 1215 (HY000): Cannot add foreign key constraint
|
Oracle 关系型数据库 OLAP
[20170421]impdp SKIP_CONSTRAINT_ERRORS
[20170421]impdp导入问题data_options=SKIP_CONSTRAINT_ERRORS.txt --//一般年前我们经常要做一些导入导出操作,经常会遇到主键冲突问题.
1482 0
|
PHP
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
334 0
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
|
SQL
ORA-02292: integrity constraint (xxxx) violated - child record found
在更新表的主键字段或DELETE数据时,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 这个是因为主外键关系,下面借助一个小列子来描述一下这个错误: SQL> create table studen...
2414 0
|
SQL
Remote table-valued function calls are not allowed
在SQL Server中,在链接服务器中调用表值函数(table-valued function)时,会遇到下面错误:   SELECT * FROM LNK_TEST.TEST.DBO.TEST(12)   消息 4122,级别 16,状态 1,第 1 行   Remote table-valued function calls are not allowed.   以前几乎没有在链接服务器(Linked Server)当中调用过表值函数,查了一下资料,看来SQL Server这似乎是不支持的(抑或是不允许)的。
1414 0