简体   繁体   English

Codeigniter数据库错误:列不存在

[英]Codeigniter Database Error: Column doesnt exist

I've followed a few tutorials online on learning the CodeIgniter framework. 我已经在线学习了一些有关学习CodeIgniter框架的教程。 I've tried to make a login and register function and everything should be working correctly however instead it shoots me back this error after I submit the register form. 我已经尝试过进行登录和注册功能,并且一切都应该正常工作,但是在我提交注册表格后,它却将我射回了这个错误。

A Database Error Occurred 发生数据库错误

Error Number: 1054 错误编号: 1054

Unknown column 'user_name' in 'field list' “字段列表”中的未知列“ user_name”

INSERT INTO 'users' ('user_name', 'user_password_hash', 'user_email') VALUES ('Test2', '$2a$08$cAkWVsvkaXvaumfcxW0gAOx2mBZMhIXxDpTQpHkOVme8l.1r9mok2', '1111') INSERT INTO'users'('user_name','user_password_hash','user_email')VALUES('Test2','$ 2a $ 08 $ cAkWVsvkaXvaumfcxW0gAOx2mBZMhIXxDpTQpHkOVme8l.1r9mok2','11

/www/application/models/user_model.php /www/application/models/user_model.php

Line Number: 41 行号:41

On line 41 of User_model.php is $this->db->insert('users'); User_model.php第41 User_model.php$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');
}

The database.php config file has been edited to include the correct database name. database.php配置文件已被编辑为包含正确的数据库名称。

I cannot figure out why it would be giving me this database error. 我不知道为什么它会给我这个数据库错误。 The column does exist. 该列确实存在。 Could it be an issue with CodeIgniter? CodeIgniter可能有问题吗?

As zack tanner mentioned in the comments running SHOW COLUMNS FROM yourDB.users; 正如zack tanner在运行SHOW COLUMNS FROM yourDB.users;的注释中提到的SHOW COLUMNS FROM yourDB.users; from a mysql command line returns with all of the columns that the mysql client can read. 从mysql命令行返回包含mysql客户端可以读取的所有列。

My PHPMYADMIN was getting old data and so running from command line displayed the realtime info. 我的PHPMYADMIN正在获取旧数据,因此从命令行运行会显示实时信息。 I was able to finish the rest of the commands through the command line in order to re structure the DB 我能够通过命令行完成其余命令,以便重新构建数据库

This may not solve your problem but when inserting user you can use a data array(); 这可能无法解决您的问题,但在插入用户时可以使用data array();。 and not have multiple db->set() 并且没有多个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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM