我在网上学习了一些关于学习CodeIgniter框架的教程。我试着做一个登录和注册功能,一切都应该正常工作,但是它却在我提交注册表格后将此错误发送回我。
发生数据库错误 错误号:
1054“字段列表”中的未知列“user_name” 插入“用户”('user_name',‘user_password_散列’,'user_email')值(‘Test2 2’,user_email '1111') /www/application/model/user_model.www 线路号码: 41
User_model.php的第41行是$this->db->insert('users');
public function add_user()
{
$passunhash = $this->input->post('password');
$passhash = $this->bcrypt->hash_password($passunhash);
$uname = $this->input->post('user_name');
$opin = $this->input->post('pin');
$this->db->set('user_name', $uname);
$this->db->set('user_password_hash', $passhash);
$this->db->set('user_email', $opin);
$this->db->insert('users');
}已编辑database.php配置文件以包含正确的数据库名称。
我不明白它为什么会给我这个数据库错误。列确实存在。这会是CodeIgniter的问题吗?
发布于 2015-09-16 17:56:23
正如在从mysql命令行运行SHOW COLUMNS FROM yourDB.users;的注释中提到的那样,mysql客户端可以读取的所有列都返回。
我的PHPMYADMIN正在获取旧数据,因此从命令行运行会显示实时信息。为了重新构造DB,我能够通过命令行完成其余的命令。
发布于 2015-09-17 06:29:43
这可能解决不了您的问题,但是当插入用户时,您可以使用一个数据数组();而不能有多个db->set()
public function add_user() {
$passunhash = $this->input->post('password');
$passhash = $this->bcrypt->hash_password($passunhash);
$data = array(
'user_name' => $this->input->post('user_name'),
'user_password_hash' => $passhash,
'user_email' => $this->input->post('pin')
);
$this->db->set($data);
$this->db->insert($this->db->dbprefix . 'users');
}https://stackoverflow.com/questions/32614602
复制相似问题