Jc John Jc John - 11 months ago 53
SQL Question

inserting data into database with condition/ codeigniter

I am a beginner in CodeIgniter and I want to insert a data in codeigniter with a where clause. Something like a query like this:

insert into tbl_check_up (bill_id) values ("bill_id") where check_up_id = "'.$check_up_id.'" ;

how can i convert it into codeigniter

Here is my codeigniter model:

var $tbl_check_up = 'tbl_check_up';

public function save_bill_checkup($check_up_id,$data) {
return $this->db->insert_id();

Here is my controller :

public function bill_id() {
$check_up_id = $this->input->post('check_up_id');
$data1 = array(
'bill_id' => $bill_id
$insert1 = $this->billing_model->save_bill_checkup($check_up_id,$data1);

Answer Source

Instead of insert, use update query.

$data = array(
           'bill_id'   => $bill_id

$this->db->where('check_up_id', $check_up_id);
$this->db->update('tbl_check_up ', $data);