报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'
2024-08-31 19:52:58
在提交注册信息的时候报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'
原因:主键冲突 违反完整性约束 字段唯一索引
从上图可以看出,用户名和邮箱必须唯一,如果填入重复的用户名或者邮箱就会出错
解决方法:在控制器里面进行判断
$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上写的。
最新文章
- Python高手之路【三】python基础之函数
- [转]别再抱怨了,国内这么多优秀的Android资源你都知道吗?
- Android进阶系列之源码分析Activity的启动流程
- js 之 continue break return 用法及注意事项
- shell算数运算
- 【 D3.js 入门系列 --- 5.1 】 做一个带坐标轴和标签的图表
- jQuery Ajax无刷新操作一般处理程序 ashx
- PYTHON seek()tell()语句
- 【leetcode】Merge Two Sorted Lists(easy)
- iOS Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962
- _vimrc默认配置
- 绝对URL和相对URL
- PHP 常用命令
- text-overflow:ellipsis 的应用(转载)
- Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换
- 超全!整理常用的iOS第三方资源
- (转)Spring boot——logback.xml 配置详解(三)<;appender>;
- jira,Confluence 的JVM内存优化
- 略解ByteBuf
- vue 思維導圖
热门文章
- python中进制转换
- element-ui select
- linux--mysql 8.0.16--裸机安装
- java_day10_多线程
- Oracle【多表查询操作(SQL92&;SQL99)】
- SQL语句复习【专题一】
- pv与pvc
- Cookie/Session的机制
- php类知识---魔术方法__toString,__call,__debugInfo
- BZOJ 2809: [Apio2012]dispatching(可并堆 左偏树板题)