php - 多插入行和表codeigniter
问题描述
我有 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);
}
这是表格和数据库
解决方案
tbcp
如果您的行nama_pt
设置了长度,请检查表,如果需要,请1
放置15
或更高。
推荐阅读
- typescript - ts 一个同时是函数和属性的类型
- active-directory - 用户主体名称问题和 LDAP
- r - 根据 dplyr 中的列在组之间保留公共行
- python - 映射字典值,而不是字典键
- javascript - 单个承诺的多个侦听器
- python - 将字典键设为行,将 dict 值设为列,一个值作为列名,一个作为列值
- angular - Angular 11:如何从多个组件共享的服务中获取对 Reactive Form 的更新
- python - 在 PyQt5 中按下特定键盘按键时将焦点放在特定的 QLineEdit 上?
- angular - 如果在 mat-date-range-picker 中禁用日期,如何禁用范围选择
- python - Networkx 邻接矩阵条件