我有1位新客户,它将插入2个表('tbcust'和'tbcp')。我在表“ tcp”中添加用于插入行的按钮“添加新联系人”,保存在表单中的按钮将插入多个表。表'tbcust'可以,但是表'tbcp'中的行'nama_pt'仅传递1个字符。
控制器
public function post_multiple_table(){
$this->load->model('Multiple_model', 'multi_model', TRUE);
$cust_input_data = array();
//$cp_input_data = array();
$cust_input_data['nama_pt'] = $this->input->post('nama_pt');
$cust_input_data['tipe'] = $this->input->post('tipe');
$cust_input_data['alamat'] = $this->input->post('alamat');
$cust_input_data['email_cust'] = $this->input->post('email_cust');
$cust_input_data['notelp'] = $this->input->post('notelp');
$cust_input_data['nofax'] = $this->input->post('nofax');
$this->form_validation->set_rules('nama_orang[]', 'nama_orang', 'required|trim|xss_clean');
$this->form_validation->set_rules('nama_pt', 'nama_orang', 'required|trim|xss_clean');
$this->form_validation->set_rules('nohp[]', 'nohp', 'required|trim|xss_clean');
$this->form_validation->set_rules('email[]', 'email', 'required|trim|xss_clean');
if ($this->form_validation->run() == FALSE){
echo validation_errors(); // tampilkan apabila ada error
}else{
$nm = $this->input->post('nama_orang');
$result = array();
foreach($nm AS $key => $val){
$result[] = array(
"nama_orang" => $_POST['nama_orang'][$key],
"nama_pt" => $_POST['nama_pt'][$key],
"nohp" => $_POST['nohp'][$key],
"email" => $_POST['email'][$key]
);
}
模型
public function create_multiple_tabel($nama_pt, $nama_orang){
$this->db->insert('tbcust', $nama_pt);
$this->db->insert_batch('tbcp', $nama_orang);
}
以及此表单和数据库
答案 0 :(得分:0)
检查表tbcp
中行nama_pt
的长度是否设置为1
,并在需要时放置15
或更高。