dongque1646 2017-06-07 08:13
浏览 92

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条回答

  • doufei16736 2017-06-07 08:19
    关注

    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);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集