AliIshaq AliIshaq - 7 months ago 36
SQL Question

CodeIgniter unable to get column names in insert function

I have the following in my 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')

which I am passing onto my model's function like so:

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

As far as I can tell, I have done all correctly, however CodeIgniter is unable to read my table's column names as it throws this error:

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

I already have my database and db helper loaded. My table structure is as follows:
client_id, client_name, client_person, client_phone
. What am I missing?


Try replace your array to this:

$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')