php - Get response from insert model in code igniter -


this controller

        $this->insert_model->form_insert($data);         $data['message'] = 'data inserted successfully';         //loading view         $this->load->view('header');         $this->load->view('post-add', $data); 

this model

function form_insert($data){     //inserting in table(students) of database(college)      $this->db->insert('adds', $data);  }     

data added model (insert_model) , showd message - data insertd successfully

but want show message either sucess or error

we can last inserted id. in codeigniter, last inserted id returns :

$this->db->insert_id(); 

i have tried below code & working fine me.

<?php             $is_insert=$this->insert_model->form_insert($data);             if($is_insert > 0)                $data['message'] = 'data inserted successfully';             else                $data['message'] = 'error in insert';             //loading view             $this->load->view('header');             $this->load->view('post-add', $data);               function form_insert($data){                //inserting in table(students) of database(college)                 $this->db->insert('adds', $data);                 return $this->db->insert_id();             }         ?> 

for ci reference please check below url: https://ellislab.com/codeigniter/user-guide/database/helpers.html


Comments