报错: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上写的。



目录
相关文章
|
4月前
Duplicate keys detected: '0'原因及解决方法
Duplicate keys detected: '0'原因及解决方法
|
4月前
|
关系型数据库 MySQL 数据库
Error: Table ‘bWAPP.users‘ doesn‘t exist
Error: Table ‘bWAPP.users‘ doesn‘t exist
60 0
|
SQL Java 数据库连接
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
196 0
|
关系型数据库 MySQL Linux
SQLSTATE[HY000]: General error: 1364 Field ‘xxx’ doesn't have a default value 解决办法
SQLSTATE[HY000]: General error: 1364 Field ‘xxx’ doesn't have a default value 解决办法
1402 0
|
数据库
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
171 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 --//一般年前我们经常要做一些导入导出操作,经常会遇到主键冲突问题.
1470 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
325 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...
2358 0
|
SQL 关系型数据库 MySQL