【问题标题】:multi insert row & table codeigniter多插入行和表codeigniter
【发布时间】:2019-01-11 02:52:45
【问题描述】:

我有 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 上的类型
  • 在表 tbcp 上,'nama_pt' 是 varchar

标签: php database codeigniter


【解决方案1】:

如果您的行nama_pt 的长度设置为1,请检查表tbcp,如果需要,请输入15 或更高。

【讨论】:

    猜你喜欢
    • 2019-07-31
    • 1970-01-01
    • 2011-04-20
    • 2020-12-12
    • 2023-03-16
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    相关资源
    最近更新 更多