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

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序