CodeIgniter Forums

Full Version: New to CI - Help with ActiveRecord Insert Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I just started using CI and have been reading the user guide and looking at as many videos as possible. I created a test form and wanted to insert the data from the form into a MySQL table. I have performed all validation and everything is working well. When I do the actual insert, I get a MySQL error that reads Unknown column '0' in 'field list'. When looking at the SQL statement that is created by AR, all the column names are numbers, 0 thru 21. There are 22 columns in my table and I am only inserting data in half the columns. The rest of the columns I am passing a NULL value. Here is my code:

public function insert()
        $this->form_validation->set_rules('contact','Contact Name','trim|required');
        $this->form_validation->set_rules('email','Email Address','trim|required|valid_email');
        $this->form_validation->set_rules('phone','Phone Number','trim|required|numeric');
        $this->form_validation->set_rules('year','Year Made','trim|required|numeric');
        $this->form_validation->set_rules('masterType','Master Type','trim|required');
        $this->form_validation->set_rules('masterStatus','Master Status','trim|required');
        $this->form_validation->set_rules('domestic','Doestic Contract','trim|required');
        $this->form_validation->set_rules('international','International Contract','trim|required');
        $this->form_validation->set_rules('international','International Contract','trim');
        if($this->form_validation->run() == FALSE){
            $new_submission_insert_data = array(
                $id = NULL,
                $substatus = 'New',
                $contact = $this->input->post('contact'),
                $email = $this->input->post('email'),
                $phone = $this->input->post('phone'),
                $title = $this->input->post('title'),
                $genre = $this->input->post('genre'),
                $length = $this->input->post('length'),
                $year = $this->input->post('year'),
                $masterType = $this->input->post('masterType'),
                $masterStatus = $this->input->post('masterStatus'),
                $domestic = $this->input->post('domestic'),
                $international = $this->input->post('international'),
                $links = $this->input->post('links'),
                $referral = NULL,
                $trailerRating = NULL,
                $keyArtRating = NULL,
                $movieRating = NULL,
                $internationalTerritories = NULL,
                $notes = NULL,
                $entered = date('Y-m-d h:i:s'),
                $updated = date('Y-m-d h:i:s')
            if($query = $this->submission_model->insert_submission($new_submission_insert_data))
                 $data['main_content'] = 'form_thankYou_view';

public function insert_submission($new_submission_insert_data)
       $insert =  $this->db->insert('submissions',$new_submission_insert_data);
       return $insert;

--Begin Error
A Database Error Occurred

Error Number: 1054

Unknown column '0' in 'field list'

INSERT INTO `submissions` (`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19`, `20`, `21`) VALUES (NULL, 'New', 'John Doe', '[email protected]', '8885551212', '1992 Sidekick Stereo', 'Western', '127', '2009', 'Digital', 'Finished', 'Never', 'Expired', '', NULL, NULL, NULL, NULL, NULL, NULL, '2012-11-13 02:59:16', '2012-11-13 02:59:16')

Filename: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\codeigniter\system\database\DB_driver.php

Line Number: 330
End Error--

I would appreciate any assistance.

thanks in advance,


El Forum

your array is not properly formed.

$new_submission_insert_data = array(
                'id' => NULL,
                'substatus' => 'New',
so on......

El Forum

Disregard my first post. My apologies, I didn't have my array in the controller setup right.

El Forum

[quote author="srpurdy" date="1352848130"]your array is not properly formed.

$new_submission_insert_data = array(
                'id' => NULL,
                'substatus' => 'New',
so on......

srpurdy, thanks. I realized it as I was going thru my controller again. Thanks for the quick response. I posted before I saw your reply.

take care.