简体   繁体   English

按钮的Codeigniter类型无法插入数据库

[英]Codeigniter type of button can't insert into database

all data insert into database already , but field city_case doesn't insert , if I replace this field by another filed such as act_id , it insert correctly , Iam sure the problem in this field in view/add.php 所有数据都已经插入数据库,但是字段city_case没有插入,如果我用act_id这样的另一个文件替换该字段,它会正确插入,我确定在view / add.php中该字段的问题。

 in controllers / cases.php function add(){ $data['fields_clients'] = $this->custom_field_model->get_custom_fields(1); $data['fields'] = $this->custom_field_model->get_custom_fields(2); $data['clients'] = $this->cases_model->get_all_clients(); $data['stages'] = $this->case_stage_model->get_all(); $data['acts'] = $this->cases_model->get_all_acts(); $data['courts'] = $this->cases_model->get_all_courts(); $data['locations'] = $this->cases_model->get_all_locations(); $data['case_categories'] = $this->cases_model->get_all_case_categories(); $data['court_categories']= $this->cases_model->get_all_court_categories(); $data['city'] = $this->cases_model->get_name_city(); //$data['employee'] = $this->cases_model->get_name_employee(); if ($this->input->server('REQUEST_METHOD') === 'POST') { $this->load->library('form_validation'); $this->form_validation->set_message('required', lang('custom_required')); $this->form_validation->set_rules('title', 'lang:title', 'required'); $this->form_validation->set_rules('client_id', 'Client', ''); $this->form_validation->set_rules('case_no', 'Case No', ''); //trim|required|is_unique[cases.case_no] $this->form_validation->set_rules('location_id', 'Location', ''); $this->form_validation->set_rules('case_stage_id', 'Case Stage', ''); $this->form_validation->set_rules('court_id', 'Court', ''); $this->form_validation->set_rules('court_category_id', 'Court Category', ''); $this->form_validation->set_rules('case_category_id', 'Case Category', ''); $this->form_validation->set_rules('act_id', 'Act', ''); $this->form_validation->set_rules('start_date', 'Filing Date', ''); $this->form_validation->set_rules('description', 'Description', ''); $this->form_validation->set_rules('city_case', 'city case', ''); $this->form_validation->set_rules('fees', 'Fees', ''); $this->form_validation->set_rules('o_lawyer', 'Opposite Lawyer', ''); $this->form_validation->set_rules('hearing_date', 'Description', ''); if ($this->form_validation->run()==true) { $save['title'] = $this->input->post('title'); $save['case_no'] = $this->input->post('case_no'); $save['client_id'] = $this->input->post('client_id'); $save['location_id'] = $this->input->post('location_id'); $save['court_id'] = $this->input->post('court_id'); $save['court_category_id'] = $this->input->post('court_category_id'); $save['case_stage_id'] = $this->input->post('case_stage_id'); $save['case_category_id'] = json_encode($this->input->post('case_category_id')); $save['act_id'] = json_encode($this->input->post('act_id')); $save['description'] = $this->input->post('description'); $save['start_date'] = $this->input->post('start_date'); $save['hearing_date'] = $this->input->post('hearing_date'); $save['o_lawyer'] = $this->input->post('o_lawyer'); $save['fees'] = $this->input->post('fees'); $save['city_case'] = json_encode($this->input->post('city_case')); $p_key = $this->cases_model->save($save); $reply = $this->input->post('reply'); if(!empty($reply)){ foreach($this->input->post('reply') as $key => $val) { $save_fields[] = array( 'custom_field_id'=> $key, 'reply'=> $val, 'table_id'=> $p_key, 'form'=> 2, ); } $this->custom_field_model->save_answer($save_fields); } $this->session->set_flashdata('message', lang('case_created')); redirect('admin/cases'); } } $data['page_title'] = lang('add') . lang('case'); $data['body'] = 'case/add'; $this->load->view('template/main', $data); } 
 models / cases_model.php function get_name_city () { $query = $this->db->get ('user_role'); return $query->result(); } 
 this is code I sure the problem in it <select name="city_case[]" class="chzn col-md-12" multiple="multiple" > <option value="">--<?php echo lang('select_city')?>--</option> <?php foreach($city as $new) { $sel = ""; if(set_select('city_case', $new->id)) $sel = "selected='selected'"; echo '<option value="'.$new->id.'" '.$sel.'>'.$new->name.'</option>'; }?> </select> I replace it with this code , it work well <input type="text" name="city_case" class="form-control" value="<?php echo set_value('city_case'); ?>"> 

, can you help me ? , 你能帮助我吗 ?

Change this line to 将此行更改为

$save['city_case'] = json_encode($this->input->post('city_case'));

To

$save['city_case'] = json_encode($this->input->post('city_case[]'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM