【发布时间】:2018-12-20 16:32:03
【问题描述】:
我尝试在 CodeIgniter 中插入我的复选框数据。但数据没有插入数据库。 这是我的视图文件:
<input type="checkbox" name="feature[]" value="WIFI" >
<input type="checkbox" name="feature[]" value="TV">
我正在尝试使用 implode 将数组转换为字符串,但是我不知道如何添加 $data 数组,所以它们一起插入
这是我的控制器:
public function save()
{
$this->load->model('Partner_model');
$feature = $this->input->post('feature');
$fea=array(
'feature'=>json_encode(implode(",",$feature))
);
$user_data= array(
'pname' => $this->input->post('pname'),
'type' => $this->input->post('type'),
'address' => $this->input->post('address'),
'about' => $this->input->post('about'),
'city' => $this->input->post('city'),
'code' => $this->input->post('code')
);
if($this->Partner_model->save($user_data,$fea))
{
$msg = "save sucesss" ;
}
else
{
$msg = "not save";
}
$this->session->set_flashdata('msg', $msg);
$this->load->view('partner_profile');
}
&这是我的模型:
public function save($data,$fea)
{
return $this->db->insert('property', $data,$fea);
}
【问题讨论】:
标签: mysql codeigniter checkbox sql-insert