我的 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/