我的控制器中有以下内容:
$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
我已经加载了数据库和db帮助程序。我的表结构如下:client_id, client_name, client_person, client_phone
。我错过了什么?
答案 0 :(得分:4)
尝试将您的数组替换为:
$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')
);