codeigniter数据未插入数据库

时间:2017-04-14 09:49:27

标签: php html codeigniter

你好每个人我是codeigniter的新手我试图在数据库中插入数据但不能正常工作。但是没有在数据库中插入数据。我是激活助手,自动加载是我写的。

我的控制器

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

我的模特

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);
}   

1 个答案:

答案 0 :(得分:1)

在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);                
    }
}

在模型中

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