Insert_batch Error Codeigniter 3.1.4

A PHP Error was encountered

Severity: Notice Message: Array to string conversion Filename: database/DB_query_builder.php Line Number: 1539 Backtrace: File: D:\xampp\htdocs\visio\application\models\projectmodel.php Line: 56 Function: insert_batch

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Array' at line 1

INSERT INTO paymentsize () VALUES ('8'), ('2017-06-07'), ('Residential'), ('L'), ('120'), ('200'), ('10000'), ('15000'), ('30'), ('12000'), ('40'), ('1000'), ('60'), ('125000'), ('10'), ('10000'), ('15000'), ('20000'), Array

Filename: D:/xampp/htdocs/visio/system/database/DB_driver.php

Line Number: 691

My Controller is:

public function store_payment()
{
    $post = array();
        $post = $this->input->post(NULL,TRUE);
        $count=count($this->input->post('pro_id'));
        echo CI_VERSION;

        for($i = 0; $i < $count; $i++){
            $post []= array(
                'pro_id'        => $post['pro_id'][$i],
                'date_add'      => $post['date_add'][$i], 
                'category'      => $post['category'][$i], 
                'type'          => $post['type'][$i], 
                'size'          => $post['size'][$i], 
                'counts'        => $post['counts'][$i], 
                'booking'       => $post['booking'][$i], 
                'confirmation'  => $post['confirmation'][$i], 
                'confirm_days'  => $post['confirm_days'][$i], 
                'allocation'    => $post['allocation'][$i], 
                'allocate_days' => $post['allocate_days'][$i], 
                'm_installment' => $post['m_installment'][$i], 
                'month'         => $post['month'][$i], 
                'y_instalment'  => $post['y_instalment'][$i], 
                'halfyear'      => $post['halfyear'][$i], 
                'leveling'      => $post['leveling'][$i], 
                'demarcation'   => $post['demarcation'][$i], 
                'possession'    => $post['possession'][$i]
                );
        }
    $this->projects->add_payment($post);
}

My Model is:

public function add_payment($array)
{
     // echo "<pre>";
     // print_r($array);
     // exit();
     return $this->db->insert_batch('paymentsize',$array);

}

My View is:

<tbody>
          <input type="hidden" name="pro_id[]"  value="<?= $project->pro_id; ?>" >
          <tr>
          <td width="14%">
            <div class="col-lg-10">
              <div class="form-group form-black label-floating is-empty">
                <label class="control-label" style="margin-top: -10px;">Date</label>
                  <input type="date" name="date_add[]" value="<?php echo date('Y-m-d'); ?>" class="form-control" >
                <span class="material-input"></span>
              </div>
              </div>
          </td>
           <td width="14%">
            <div class="col-lg-10">
                <div class="form-group form-black label-floating is-empty">
                  <label class="control-label">Plot Category</label>
                    <select name="category[]" class="form-control">
                      <option> </option>
                      <option>Residential</option>
                      <option>Commercial</option>
                    </select>
                  <span class="material-input"></span>
                </div>
              </div>
           </td>
           <td>

if i use print_r it shows all array elements with respective Values.. but it is not inserting in DB Table.. my view has a table with 17 text fields... i just mention few for an Example... waiting for help.... :) Thank you in advance...

2个回答



将控制器更改为以下代码,</ p>

  public function store_payment()
{
$ post = array();
$ post = $ this-&gt; input-&gt; post(NULL,TRUE);
$ count = count($ this-&gt; input-&gt; post(' pro_id'));
echo CI_VERSION;

for($ i = 0; $ i&lt; $ count; $ i ++){
$ post = array(
'pro_id'=&gt; $ post [ 'pro_id'] [$ i],
'date_add'=&gt; $ post ['date_add'] [$ i],
'category'=&gt; $ post ['category'] [$ i],\ n'type'=&gt; $ post ['type'] [$ i],
'size'=&gt; $ post ['size'] [$ i],
'counts'=&gt; $ post [ '计数'] [$ i],
'预订'=&gt; $ post ['预订'] [$ i],
'确认'=&gt; $ post ['确认'] [$ i],\ n'confirm_days'=&gt; $ post ['confirm_days'] [$ i],
'allocation'=&gt; $ post ['allocation'] [$ i] ,
'allocate_days'=&gt; $ post ['allocate_days'] [$ i],
'm_installment'=&gt; $ post ['m_installment'] [$ i],
'month'=&gt; $ post ['month'] [$ i],
'y_instalment'=&gt; $ post ['y_instalment'] [$ i],
'halfyear'=&gt; $ post ['halfyear'] [$ i],
'leveling'=&gt; $ post ['leveling'] [$ i],
'demarcation'=&gt; $ post ['demarcation'] [$ i],
'trustssion'=&gt; $ post ['possession'] [$ i]
);
}
$ this-&gt; projects-&gt; add_payment($ post);
}
</ code> </ pre>
</ DIV>

展开原文

原文

Change your controller as following code,

public function store_payment()
{
    $post = array();
        $post = $this->input->post(NULL,TRUE);
        $count=count($this->input->post('pro_id'));
        echo CI_VERSION;

        for($i = 0; $i < $count; $i++){
            $post = array(
                'pro_id'        => $post['pro_id'][$i],
                'date_add'      => $post['date_add'][$i], 
                'category'      => $post['category'][$i], 
                'type'          => $post['type'][$i], 
                'size'          => $post['size'][$i], 
                'counts'        => $post['counts'][$i], 
                'booking'       => $post['booking'][$i], 
                'confirmation'  => $post['confirmation'][$i], 
                'confirm_days'  => $post['confirm_days'][$i], 
                'allocation'    => $post['allocation'][$i], 
                'allocate_days' => $post['allocate_days'][$i], 
                'm_installment' => $post['m_installment'][$i], 
                'month'         => $post['month'][$i], 
                'y_instalment'  => $post['y_instalment'][$i], 
                'halfyear'      => $post['halfyear'][$i], 
                'leveling'      => $post['leveling'][$i], 
                'demarcation'   => $post['demarcation'][$i], 
                'possession'    => $post['possession'][$i]
                );
        }
    $this->projects->add_payment($post);
}



您将 $ post </ code>用于两个目的,将控制器代码更改为以下代码:</ p> \ n

  public function store_payment()
{
$ post = $ this-&gt; input-&gt; post(NULL,TRUE);
$ count = count($ this-&gt; input-&gt; post('pro_id'));
echo CI_VERSION;

$ data = array();
for($ i = 0; $ i&lt; $ count; $ i ++){
$ data [] = array(
'pro_id'=&gt; $ post ['pro_id'] [$ i],
'date_add'=&gt; $ post ['date_add'] [$ i],
' category'=&gt; $ post ['category'] [$ i],
'type'=&gt; $ post ['type'] [$ i],
'size'=&gt; $ post ['size '] [$ i],
'计数'=&gt; $ post ['计数'] [$ i],
'预订'=&gt; $ post ['booking'] [$ i],
' 确认'=&gt; $ post ['确认'] [$ i],
'confirm_days'=&gt; $ post ['confirm_days'] [$ i],
'分配'=&gt; $ post ['分配 '] [$ i],
'allocate_days'=&gt; $ post ['allocate_days'] [$ i],
'm_installment'=&gt; $ post ['m_installment'] [$ i],
'month'=&gt; $ post ['month'] [$ i],
'y_instalment'=&gt; $ post ['y_instalment'] [$ i],
'halfyear'=&gt; $ post ['halfyear'] [$ i],
'leveling'=&gt; $ post ['leveling'] [$ i],
'demarcation'=&gt; $ post ['demarcation'] [$ i],
'trustssion'=&gt; $ post ['possession'] [$ i]
);
}
$ this-&gt; projects-&gt; add_payment($ data);
}
</ code> </ pre>
</ DIV>

展开原文

原文

You used $post for two purpose, change your controller codes as following code:

public function store_payment()
{
    $post = $this->input->post(NULL,TRUE);
    $count=count($this->input->post('pro_id'));
    echo CI_VERSION;

    $data = array();
    for($i = 0; $i < $count; $i++){
        $data []= array(
            'pro_id'        => $post['pro_id'][$i],
            'date_add'      => $post['date_add'][$i], 
            'category'      => $post['category'][$i], 
            'type'          => $post['type'][$i], 
            'size'          => $post['size'][$i], 
            'counts'        => $post['counts'][$i], 
            'booking'       => $post['booking'][$i], 
            'confirmation'  => $post['confirmation'][$i], 
            'confirm_days'  => $post['confirm_days'][$i], 
            'allocation'    => $post['allocation'][$i], 
            'allocate_days' => $post['allocate_days'][$i], 
            'm_installment' => $post['m_installment'][$i], 
            'month'         => $post['month'][$i], 
            'y_instalment'  => $post['y_instalment'][$i], 
            'halfyear'      => $post['halfyear'][$i], 
            'leveling'      => $post['leveling'][$i], 
            'demarcation'   => $post['demarcation'][$i], 
            'possession'    => $post['possession'][$i]
            );
    }
    $this->projects->add_payment($data);
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐