严重性:注意 消息:数组到字符串转换 文件名:database / DB_query_builder.php 行号:1539 Backtrace:文件:D:\ xampp \ htdocs \ visio \ application \ models \ projectmodel.php 行:56 功能:insert_batch
错误号码:1064
您的SQL语法有错误;检查与MariaDB服务器版本对应的手册,以便在第1行的“Array”附近使用正确的语法
INSERT INTO paymentsize
()VALUES('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它会显示具有相应值的所有数组元素..但它不会插入数据库表.. 我的视图有一个包含17个文本字段的表...我只提一些例子...... 等待帮助...... :) 提前谢谢你......
答案 0 :(得分: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);
}
答案 1 :(得分:0)
您将$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);
}