phpcodeignitermodel-view-controllersql-insertsubmission

CodeIgniter model method which collects submission data fails to insert record without editing an error


I was trying to insert data in database, but it's not working properly. There's no data inserted data in database and no error. I activated the helper and auto-load is written.

my controller

public function save()
{
    if ($this->input->post('submit')) {
        $this->Checkout_model->process();                
    }
}

my model

function process()
{
    $name = $this->input->post('name');
    $phone = $this->input->post('phone');
    $email = $this->input->post('email');
    $address = $this->input->post('address');
    $data = array(
        'name' => $name,
        'phone' => $phone,
        'email' => $email,
        'address' => $address               
    );
    $this->db->insert('customers', $data);
}

Solution

  • Use this code In Controller

    public function save() {
        if($this->input->post('submit')) {
        $name = $this->input->post('name');
        $phone = $this->input->post('phone');
        $email = $this->input->post('email');
        $address = $this->input->post('address');
        $data=array (
            'name' => $name,
            'phone' => $phone,
            'email' => $email,
            'address' => $address               
        );
            $this->Checkout_model->process($data);                
        }
    }
    

    In Model

    function process($data) { 
        $this->db->insert('customers',$data);
    }