直接上代码:
$openid = $userInfo['openid'];
$model_user = M('user');
$result_user = $model_user->where(['is_del'=>0,'username'=>$openid])->find();
if($result_user && is_array($result_user)){
$_SESSION['id'] = $result_user['id'];
}else{
$openid = $userInfo['openid'];
$_SESSION['openid'] = $openid;
$gender = $userInfo['sex'];
$data = [
'username' => $openid,
'password' => '',
'salt' => '',
'gender' => $gender,
'email' => '',
'mobile' => '',
'is_del' => 0 ,
];
if($model_user->add($data)){
$this->success('入库成功');
}
$openid已经得到值,在外面或数组内直接var_dumpdou能得到它的值,就是入数据库就直接提示
1048:Column 'username' cannot be null [ SQL语句 ] :
INSERT INTO `user` (`username`,`password`,`salt`,`gender`,`email`,`mobile`,`is_del`)
VALUES (NULL,'','',NULL,'','','0')
没有遇到过,如果知道是什么原因的请指点一下,谢谢