0

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?

5
  • 1
    print $client_data.what is the output? Commented Jul 7, 2016 at 11:48
  • Does your query NSERT INTO clients (0, 1, 2, 3) ..... is working in PhpMyAdmin ? Commented Jul 7, 2016 at 11:48
  • @Saty added my column names. Query will not work because that is not the correct column names. Commented Jul 7, 2016 at 11:48
  • In array declaration change $client_id = null, to 'client_id' => null, ets Commented Jul 7, 2016 at 11:49
  • 'client_id' =>null you should pass associate array' Commented Jul 7, 2016 at 11:49

1 Answer 1

4

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')
);
Sign up to request clarification or add additional context in comments.

2 Comments

Yep! This was it. Just a syntax mistake, thank you for pointing out.
@AliIshaq you're welcome ) don't forget to mark the question as solved ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.