我正在尝试构建一个投标应用程序。我想将文本字段与输出行的主键相关联。例如文本字段是 bid_amount 。当您输入出价金额时,我希望输入的出价金额以及出价者(卡车ID)和出价产品(行李ID)存储在出价表中。输出的要投标的产品存储在另一个表(寄售表)中,下面是我的模型、 View 和 Controller 。
以下是出现的错误
发生数据库错误
Error Number: 1054
Unknown column 'Array' in 'field list'
UPDATE `bids` SET `luggage_id` = NULL, `bid_amount` = Array, `truckerid` = '84K7B7'
Filename: models/Truckeraccount_model.php
Line Number: 129
遇到 PHP 错误
Severity: Notice
Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1524
下面是我的模型、 View 和 Controller 。
查看
<h2 class="page-header">
<i class="fa fa-legal"></i>   <font color="orange"> Loads To Bid For </font>
</h2>
</div><!-- /.col -->
</div>
<?php
foreach ($h->result() as $row)
{
?>
<div class="row invoice-info">
<div class="col-sm-1 invoice-col">
</div>
<div class="col-sm-3 invoice-col">
<img src="<?php echo base_url()?>/res/images/goods/1.png">
</div>
<div class="col-sm-4 invoice-col">
<address>
Description: <?php echo $row->description;?><br>
Location Address: <?php echo $row->l_area;?><br>
Destination Address: <?php echo $row->d_area;?><br>
Date: <?php echo $row->dom;?><br>
Time: <?php echo $row->tom;?>
</address>
</div>
<div class="col-sm-2 invoice-col">
<address>
</address>
</div><!-- /.col -->
<div class="col-sm-2 invoice-col">
<?php echo form_open('truckeraccount_ctrl/bid'); ?>
<input type="hidden" class="form-control" name="truckerid" value="<?php
$truckerid = $this->session->userdata('truckerid');
echo $truckerid; ?>" required>
<input type="text" class="form-control" name="bid_amount[$row->luggage_id]" placeholder="Bid">
<button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
</div>
</div>
Controller
public function bid(){
$this->load->model('Truckeraccount_model');
// $luggage_id = $this->uri->segment(3);
$this->Truckeraccount_model->bid();
redirect('truckeraccount_ctrl');
}
型号
function bid(){
$data = array(
'luggage_id' => $this->input->post('luggage_id'),
'bid_amount' => $this->input->post('bid_amount'),
'truckerid' => $this->input->post('truckerid')
);
//$this->db->where('luggage_id', $luggage_id);
$query=$this->db->update('bids', $data);
return $query;
}
最佳答案
错误出现在表单的bid_amount[$row->luggage_id]部分。字段名称中不能包含第三个括号,如果写入,它将被视为数组。
关于php - 使用 codeigniter 将出价放入出价表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37563360/