【问题标题】:Insert_batch Error Codeigniter 3.1.4Insert_batch 错误 Codeigniter 3.1.4
【发布时间】:2017-11-08 11:31:55
【问题描述】:

遇到 PHP 错误

严重性:通知 消息:数组到字符串的转换 文件名:数据库/DB_query_builder.php 行号:1539 回溯:文件:D:\xampp\htdocs\visio\application\models\projectmodel.php 线路:56 函数:insert_batch

发生数据库错误

错误号:1064

您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的“数组”附近使用的正确语法

插入paymentsize () 值 ('8'), ('2017-06-07'), ('Residential'), ('L'), ('120'), ('200') , ('10000'), ('15000'), ('30'), ('12000'), ('40'), ('1000'), ('60'), ('125000'), ( '10'), ('10000'), ('15000'), ('20000'), 数组

文件名:D:/xampp/htdocs/visio/system/database/DB_driver.php

行号:691

我的控制器是:

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

我的模特是:

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

我的观点是:

<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>

如果我使用 print_r,它会显示具有各自值的所有数组元素.. 但它没有插入 DB 表中.. 我的视图有一个包含 17 个文本字段的表格......我只是提到了几个例子...... 等待帮助.... :) 提前谢谢你...

【问题讨论】:

    标签: php mysql arrays codeigniter


    【解决方案1】:

    将控制器更改为以下代码,

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

    【讨论】:

      【解决方案2】:

      您将$post 用于两个目的,将您的控制器代码更改为以下代码:

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

      【讨论】:

        猜你喜欢
        • 2014-02-07
        • 1970-01-01
        • 2016-09-03
        • 1970-01-01
        • 2017-02-13
        • 2015-01-28
        • 1970-01-01
        • 1970-01-01
        • 2014-04-07
        相关资源
        最近更新 更多