这里有两个名为services和payment的表,我有两个表格,用于插入值...当我输入数据到服务时,我得到两行名称id和customer_id,我想生成这些值到支付表,同时添加到相应的ID ..这是我的服务表..
ini_set('memory_limit','20M');
这是我的付款表
id code customer_id particulars serialno complaint
22 ORD00022 16 tv 100 ddfds
23 ORD00023 19 GH 565 gfdg
24 ORD00024 15 tv 122 sdfsd
25 ORD00025 16 cvbcv 5 tgtdfgfg
26 ORD00026 16 cvbcv 5 tgtdfgfg
这是我的观点页面
id order_id customer_id actual_amount paid_amount balance type
3 0 0 250.00 100.00 150.00 Cash
4 0 0 250.00 50.00 100.00 Cash
5 0 0 150.00 50.00 100.00 Credit
10 0 0 500.00 500.00 400.00 Credit
13 26 16 250.00 100.00 0.00 Cash
我的控制器看起来像这样..
<li> <a href="" class="make_payment" data-toggle="modal" data-target=".payment" id="<?php echo $row->id; ?>" customer-id="<?php echo $row->customer_id; ?>" >Make Payment</a> </li>
<div class="modal payment">
<div class="modal-dialog">
<form action="<?php echo base_url(); ?>account_control/make_payment" method="post" id="assign-form">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Make Payment</h4>
</div>
<div class="modal-body">
<div class="box-body">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Total Amount</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="total_amount" id="total_amount" placeholder="Total Amount">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Paid Amount</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="paid_amount" id="paid_amount" placeholder="Paid Amount">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Balance</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="balance" id="balance" placeholder="Balance">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Balance</label>
<div class="col-sm-10">
<select name="type" class="form-control">
<option value="Cash">Cash</option>
<option value="Credit">Credit</option>
</select>
</div>
<div class="clearfix"></div>
</div>
<input type="hidden" name="order_id" id="order_id">
<input type="hidden" name="customer_id" id="customer_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Pay">
</div>
我的模型看起来像这样
public function make_payment()
{
$status = $this->Account_model->make_payment();
if($status)
{
$this->session->set_flashdata('message','Payment successful');
}
else
{
$this->session->set_flashdata('message','Payment Failed');
}
redirect('account_control/view_order');
}
我得到这样的错误
public function make_payment()
{
$paid = $this->input->post('paid_amount');
$total = $this->input->post('total_amount');
$balance = $this->input->post('balance');
$customer_id = $this->input->post('customer_id');
$order_id = $this->input->post('order_id');
$data = array('order_id' => $order_id,
'customer_id' => $customer_id,
'actual_amount'=>$total,
'paid_amount' => $paid,
'balance' => $balance
);
if($this->db->insert('payment',$data))
{
return TRUE;
}
else
{
return FALSE;
}
}
这是我的输出视图,来自下面的makep付款操作显示模态
Error Number: 1048
Column 'order_id' cannot be null
INSERT INTO `payment` (`order_id`, `customer_id`, `actual_amount`, `paid_amount`, `balance`) VALUES (NULL, 'NULL', '100', '50', '50')
Filename: C:/wamp64/www/account/application/models/Account_model.php
Line Number: 196
我在支付表中插入的最后一行是我假设我应该得到的值
答案 0 :(得分:1)
在您的表单 order_id,customer_id 隐藏归档缺失value
属性
示例:
<input type="hidden" name="order_id" value="12" id="order_id">
<input type="hidden" name="customer_id" value="454" id="customer_id">
答案 1 :(得分:0)
如果您收到Column 'order_id' cannot be null
表示您的order_id
未发布或已过帐,则表示该值为空。
请检查您是否在插入时间内获得order_id
。