你好每个人我是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);
}
答案 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);
}