![图片上传中...]
public function addUserBasicData($username,$password,$user_type,$email,$phone,$onlyuid = '598E0CD9'){ if (empty($username)) { $username = "用户".mt_rand(); } $data['username'] = $username; $data['onlyuid'] = $onlyuid; $data['password'] = $password; $data['user_type'] = $user_type; $data['email'] = $email; $data['phone'] = $phone; $data['regdate'] = NOW_TIME; $rules = array( array('onlyuid','','身份重复',0,'unique',1), array('phone','require','手机号码非法','/^(13|14|15|16|17|18)\d{9}$$/'), array('phone','','您输入手机号码已经被注册!',0,'unique',1), array('email','','您输入电子邮箱已经被注册!',0,'unique',1), array('password','require','您尚未填写密码!'), array('user_type','require','您尚未选择用户类型!'), array('repassword','password','确认密码不正确',0,'confirm'), array('password','checkPwd','密码格式不正确',0,'function'), ); if (!$this->table('yy_common_member')->validate($rules)->create()){ $return_value["status"] = "failed"; $return_value["status_code"] = 40000; $return_value["status_message"] = $this->getError();; $return_value["data"]= ""; return $return_value; }else{ $uid = $this->table('yy_common_member')->add($data); $data2['uid'] = $uid; $return_value["status"] = "success"; $return_value["status_code"] = 20105; $return_value["status_message"] = ""; $return_value["data"]= $this->table('yy_common_member_profile')->add($data2); return $return_value; } }
以上是代码片段
分别设置了
array('onlyuid','','身份重复',0,'unique',1), 和 array('phone','','您输入手机号码已经被注册!',0,'unique',1),
的验证规则。
但前者不生效,后者可以使用
报错
正常
This is obviously an error reported by the sql statement. It has nothing to do with verification. The onlyuid inserted is repeated
What is the data type of the onlyuid field in your database?
Everyone is right: the reason is in the database, you are trying to insert a duplicate onlyuid, and this field is obviously set to be unique.
Check it. If the literal meaning of this field is not very strong, it is recommended to use the auto-increment form. Do not skip this field directly every time you insert data and let it increase by itself.
There is also a possibility that the value to be inserted in this field has exceeded its maximum allowed value.