insert data into database with codeigniter insert data into database with codeigniter codeigniter codeigniter

insert data into database with codeigniter


Try this in your model:

function order_summary_insert()    $OrderLines=$this->input->post('orderlines');    $CustomerName=$this->input->post('customer');    $data = array(        'OrderLines'=>$OrderLines,        'CustomerName'=>$CustomerName    );    $this->db->insert('Customer_Orders',$data);}

Try to use controller just to control the view and models always post your values in model. it makes easy to understand.Your controller will be:

function new_blank_order_summary() {    $this->sales_model->order_summary_insert($data);    $this->load->view('sales/new_blank_order_summary');}


It will be better for you to write your code like this.

In your Controller Write this code.

    function new_blank_order_summary() {     $query = $this->sales_model->order_summary_insert();     if($query) {        $this->load->view('sales/new_blank_order_summary');     } else {        $this->load->view('sales/data_insertion_failed');    }  }

and in your Model

function order_summary_insert() {    $orderLines = trim(xss_clean($this->input->post('orderlines')));    $customerName = trim(xss_clean($this->input->post('customer')));    $data = array(        'OrderLines'=>$orderLines,        'CustomerName'=>$customerName    );    $this->db->insert('Customer_Orders',$data);    return ($this->db->affected_rows() != 1) ? false : true;}


function saveProfile(){    $firstname = $this->input->post('firstname');    $lastname = $this->input->post('lastname');    $post_data = array('firstname'=> $firstname,'lastname'=>$lastname);    $this->db->insert('posts',$post_data);    return $this->db->insert_id(); }