在提交注册信息的时候报错: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上写的。

最新文章

  1. Python高手之路【三】python基础之函数
  2. [转]别再抱怨了,国内这么多优秀的Android资源你都知道吗?
  3. Android进阶系列之源码分析Activity的启动流程
  4. js 之 continue break return 用法及注意事项
  5. shell算数运算
  6. 【 D3.js 入门系列 --- 5.1 】 做一个带坐标轴和标签的图表
  7. jQuery Ajax无刷新操作一般处理程序 ashx
  8. PYTHON seek()tell()语句
  9. 【leetcode】Merge Two Sorted Lists(easy)
  10. iOS Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962
  11. _vimrc默认配置
  12. 绝对URL和相对URL
  13. PHP 常用命令
  14. text-overflow:ellipsis 的应用(转载)
  15. Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换
  16. 超全!整理常用的iOS第三方资源
  17. (转)Spring boot——logback.xml 配置详解(三)<appender>
  18. jira,Confluence 的JVM内存优化
  19. 略解ByteBuf
  20. vue 思維導圖

热门文章

  1. python中进制转换
  2. element-ui select
  3. linux--mysql 8.0.16--裸机安装
  4. java_day10_多线程
  5. Oracle【多表查询操作(SQL92&SQL99)】
  6. SQL语句复习【专题一】
  7. pv与pvc
  8. Cookie/Session的机制
  9. php类知识---魔术方法__toString,__call,__debugInfo
  10. BZOJ 2809: [Apio2012]dispatching(可并堆 左偏树板题)