Using $this->db->insert_id();

#1
[eluser]snowstar[/eluser]
Hi All,

Im having some issues using $this->db->insert_id();

i think this is mostly due to not knowing how to use it properly.

Basically im inserting data into two tables from one form, using $this->db->insert_id(); to recall the id used in the first array.

below is my controller and the error im getting.

can any one help point me in the right direction?

My controller
Code:
function add()
    {
        
        // Load the model
        $this->load->model('sales/sales');
        
        $data1 = array(
            'clientid' => $this->input->post('clientid'),
            'userid' => $this->input->post('userid'),
            'date' => $this->input->post('date'),
            'totalprice' => $this->input->post('totalprice'),
            'paymenttype' => $this->input->post('paymenttype'),
            'chequeid' => $this->input->post('chequeid'),
            'bank' => $this->input->post('bank'),
            'branch' => $this->input->post('branch'),
        );
        
        
        $this->sale_model->add_one($data1);
        
        $id = $this->db->insert_id();
        
        $data2 = array(
            'prodid' => $this->input->post('prodid'),
            'qty' => $this->input->post('qty'),
            $id => $this->input->post('orderid'),
        );
        
        $this->sale_model->add_two($data2);
        
        // Load View after submit
        $this->index();
    }

The Error
Quote:A Database Error Occurred

Error Number: 1054

Unknown column '123184' in 'field list'

INSERT INTO `mytable` (`prodid`, `qty`, `123184`) VALUES ('IG101', '1', 0)

#2
[eluser]snowstar[/eluser]
and two seconds after i post this i see where i went wrong

The fix
Code:
'orderid' => $id


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.