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

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
function add()
        // Load the model
        $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'),
        $id = $this->db->insert_id();
        $data2 = array(
            'prodid' => $this->input->post('prodid'),
            'qty' => $this->input->post('qty'),
            $id => $this->input->post('orderid'),
        // Load View after submit

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)

and two seconds after i post this i see where i went wrong

The fix
'orderid' => $id

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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