【问题标题】:Database help needed i'm stumped需要数据库帮助我很难过
【发布时间】:2016-02-04 03:45:29
【问题描述】:

我最近在按照安装说明下载了一些使用 codeigniter 框架制作的软件后,我在 localhost 上运行了网站,它加载了,但是当我注册一个新成员时,它给了我以下错误。我对所有这些都是全新的,所以对你来说似乎微不足道的事情对我来说可能不会只是提醒。

错误号:1054 '字段列表'中的未知列'activation_hash' INSERT INTO `bw_users` (`password`, `location`, `register_time`, `salt`,`activation_hash`,`activation_id`,`email_address`, `email_activated`, `user_hash`, `user_name`, `user_role`, `public_key`,`private_key`,`private_key_salt`,`wallet_salt`, `local_currency`) 值 $2a$10$51GaLf4o644Rb/FxR8Os9enxWuop1V.haISOHzinT1Tq674.5SaXm', '224', 1454533259, '$2a$10$51GaLf4o644Rb/FxR8Os9hA2gGDxVQ==', 'f0a57fb24bcda7bd87e26bc9bafb71ee','ae7522de65812b','','1', '2eb1a2c0b086bf044a80',

文件名:models/Users_model.php

行号:37

我提取了 Users_model 第 37 行及其周围的代码

public function add($data, $token_info = NULL)
{
    $ret = $this->db->insert('users', $data) == TRUE;   <<<<<<<<  This is line 37
    if ($token_info !== null)
        $this->delete_registration_token($token_info['id']);

    return $ret;
}

然后我检查了剩下的activation_hash代码,我唯一能看到的地方是users_model.php的底部,如下所示。

public function attempt_email_activation($identifier, $subject, $activation_hash)
{
    $q = $this->db->select('id, email_activated')->get_where('users', array($identifier => $subject, 'activation_hash' => $activation_hash));
    if ($q->num_rows() > 0) {
        $row = $q->row_array();
        if ($row['email_activated'] == '1') {
            return 'activated';
        } else {
            $this->_set_activated_email($row['id']);
            return TRUE;
        }
    }
    return FALSE;
}

这是我的 sql 数据库的 bw_users 部分,如果需要,我可以发布整个数据库转储。

CREATE TABLE IF NOT EXISTS `bw_users` (
  `id` int(9) NOT NULL AUTO_INCREMENT,
  `banned` enum('0','1') DEFAULT '0',
  `block_non_pgp` enum('0','1') DEFAULT '0',
  `entry_paid` enum('0','1') DEFAULT '0',
  `force_pgp_messages` enum('0','1') DEFAULT '0',
  `location` int(3) NOT NULL,
  `login_time` int(20) NOT NULL,
  `display_login_time` enum('0','1') DEFAULT '0',
  `password` varchar(128) NOT NULL,
  `public_key` blob NOT NULL,
  `private_key` blob NOT NULL,
  `private_key_salt` varchar(64) NOT NULL,
  `register_time` int(20) NOT NULL,
  `salt` varchar(128) NOT NULL,
  `wallet_salt` varchar(128) NOT NULL,
  `user_hash` varchar(25) NOT NULL,
  `user_name` varchar(40) NOT NULL,
  `user_role` enum('Buyer','Vendor','Admin') NOT NULL,
  `local_currency` int(11) NOT NULL,
  `completed_order_count` int(9)  DEFAULT '0',
  `totp_secret` varchar(25),
  `totp_two_factor` enum('0','1') DEFAULT '0',
  `pgp_two_factor` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_hash` (`user_hash`,`user_name`),
  KEY `user_name`  (`user_name`,`user_hash`,`banned`,`entry_paid`,`register_time`,`user_role`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT INTO `bw_users` (`banned`, `block_non_pgp`, `entry_paid`,     `force_pgp_messages`, `location`, `login_time`, `display_login_time`, `password`, `public_key`, `private_key`, `private_key_salt`, `register_time`, `salt`, `pgp_two_factor`, `user_hash`, `user_name`, `user_role`, `local_currency`, `completed_order_count`, `totp_two_factor`, `totp_secret`) VALUES
('0', '0', '1', '0', 1, 0, '0', '%PASSWORD%', '%PUBLIC_KEY%', '%PRIVATE_KEY%', '%PRIVATE_KEY_SALT%', '%REGISTER_TIME%', '%SALT%', '0', '%USER_HASH%', 'admin', 'Admin', 0, 0, '0', '');

有人可以告诉我我需要做什么,以消除此错误并能够注册用户,我整天都在试图解决这个问题,这让我发疯了。感谢您的帮助。

编辑 ----------------------------------------

感谢到目前为止的回复,我根据@Vũ Tuấn Anh 提供的信息对表格进行了如下修改

更改表 bw_users 添加列activation_hash VARCHAR(128), 添加列activation_id VARCHAR(128), 添加列email_address VARCHAR(64),
添加列email_activatedSMALLINT(4);

CREATE TABLE IF NOT EXISTS `bw_users` (
  `id` int(9) NOT NULL AUTO_INCREMENT,
  `banned` enum('0','1') DEFAULT '0',
  `block_non_pgp` enum('0','1') DEFAULT '0',
  `entry_paid` enum('0','1') DEFAULT '0',
  `force_pgp_messages` enum('0','1') DEFAULT '0',
  `location` int(3) NOT NULL,
  `login_time` int(20) NOT NULL,
  `display_login_time` enum('0','1') DEFAULT '0',
  `password` varchar(128) NOT NULL,
  `public_key` blob NOT NULL,
  `private_key` blob NOT NULL,
  `private_key_salt` varchar(64) NOT NULL,
  `register_time` int(20) NOT NULL,
  `salt` varchar(128) NOT NULL,
  `wallet_salt` varchar(128) NOT NULL,
  `user_hash` varchar(25) NOT NULL,
  `user_name` varchar(40) NOT NULL,
  `user_role` enum('Buyer','Vendor','Admin') NOT NULL,
  `local_currency` int(11) NOT NULL,
  `completed_order_count` int(9)  DEFAULT '0',
  `totp_secret` varchar(25),
  `totp_two_factor` enum('0','1') DEFAULT '0',
  `pgp_two_factor` enum('0','1') DEFAULT '0',
  'activation_hash' varchar(128),
  'activation_id' varchar(128),
  'email address' varchar(64),
  'email_activated' smallint(4),
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_hash` (`user_hash`,`user_name`),
  KEY `user_name` (`user_name`,`user_hash`,`banned`,`entry_paid`,`register_time`,`user_role`, 'activation_has', 'activation_id', 'email_address', 'email_activated')
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT INTO `bw_users` (`banned`, `block_non_pgp`, `entry_paid`, `force_pgp_messages`, `location`, `login_time`, `display_login_time`, `password`, `public_key`, `private_key`, `private_key_salt`, `register_time`, `salt`, `pgp_two_factor`, `user_hash`, `user_name`, `user_role`, `local_currency`, `completed_order_count`, `totp_two_factor`, `totp_secret`, 'activation_hash', 'activation_id', 'email_address', 'email_activated') VALUES
('0', '0', '1', '0', 1, 0, '0', '%PASSWORD%', '%PUBLIC_KEY%', '%PRIVATE_KEY%', '%PRIVATE_KEY_SALT%', '%REGISTER_TIME%', '%SALT%', '0', '%USER_HASH%', 'admin', 'Admin', 0, 0, '0', '');

现在的问题是当我再次添加数据库时,它说存在语法错误并且不会添加新行,我在这里做错了什么?

在底部我是否也将它们放入插入代码中,我是否需要将它们或它们中的任何一个移动到主键、唯一键或键行?

【问题讨论】:

  • 您需要将activation_hash列添加到表格中。
  • 你能登录数据库并发布desc users的输出吗?
  • 在第 37 行之前发布 var_dump($data)。您的表缺少 activation_hash

标签: php codeigniter mysqli


【解决方案1】:

修改您的表格:

ALTER TABLE bw_users
ADD COLUMN `activation_hash` VARCHAR(128), 
ADD COLUMN `activation_id` VARCHAR(128), 
ADD COLUMN `email_address` VARCHAR(64), 
ADD COLUMN `email_activated` SMALLINT(4);

问题更新后的编辑答案:

您的 sql 插入语句在使用 ' 字符时有基本错误。请使用`如下:

插入bw_users (banned, block_non_pgp, entry_paid, force_pgp_messages, location, login_time, display_login_time, password, @98765433@2, @98765433@2, @98765433@2 987654334@, register_time, salt, pgp_two_factor, user_hash, user_name, user_role, local_currency, completed_order_count, totp_two_factor, totp_secret, activation_hash, activation_id , email_address, email_activated) 价值观 ('0', '0', '1', '0', 1, 0, '0', '%PASSWORD%', '%PUBLIC_KEY%', '%PRIVATE_KEY%', '%PRIVATE_KEY_SALT%', ' %REGISTER_TIME%', '%SALT%', '0', '%USER_HASH%', 'admin', 'Admin', 0, 0, '0', '');

更多细节: 你的老:

'activation_hash' => `activation_hash`
'activation_id'   => `activation_id`
'email_address'   => `email_address`
'email_activated' => `email_activated`

如果遇到语法错误,请仔细检查语法。很简单。

【讨论】:

  • 我用您提供的信息编辑了原始帖子,当我尝试导入数据库时​​出现语法错误,您可以在有空的时候看看编辑。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多