php - CodeIgniter 无法在插入函数中获取列名

标签 php mysql codeigniter insert

我的 Controller 中有以下内容:

$client_data = array(
    $client_id = null,
    $client_name = $this->input->post('client_name'),
    $client_contact = $this->input->post('client_contact'),
    $client_phone = $this->input->post('client_phone')
);

我像这样传递给我模型的函数:

public function add_client($client_data) {
    $this->db->insert('clients', $client_data);
}

据我所知,我所做的一切都是正确的,但是 CodeIgniter 无法读取我的表的列名,因为它抛出了这个错误:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 1, 2, 3) VALUES (NULL, 'Test Client', '' at line 1

INSERT INTO `clients` (0, 1, 2, 3) VALUES (NULL, 'Test Client', 'Test Person', '123486')

Filename: C:/wamp64/www/foobar/system/database/DB_driver.php

Line Number: 691

我已经加载了我的数据库和数据库助手。我的表结构如下:client_id, client_name, client_person, client_phone。我错过了什么?

最佳答案

尝试将您的数组替换为:

$client_data = array(
    'client_id' => null,
    'client_name' => $this->input->post('client_name'),
    'client_contact' => $this->input->post('client_contact'),
    'client_phone' => $this->input->post('client_phone')
);

关于php - CodeIgniter 无法在插入函数中获取列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38244668/

相关文章:

php - 无法从 MySQL 查询获得正确的输出

Codeigniter 表单验证允许数字类型包含逗号

php - 为什么 PHP PDO 在 mysql 命令行工作时得到 "SQLSTATE[42000] [1044] Access denied for user"?

php - 本地主机 NodeJS 和 PHP 在同一域中

python - mysql.connector.errors.ProgrammingError : 1064 (42000): You have an error in your SQL syntax; for the right syntax to use near ')' at line 1

mysql - 从一个表中的总和中减去另一个表中的总和

php - 编辑 2 - 用于清除和转义动态 MySQL 中使用的任何变量的 PHP 函数 - 我的代码

php - date() 函数的问题

php - 代码点火器 "where"和 "or_where"

php codeigniter 不更新变量到 mysql