这里有两个名为services和payment的表,我有两个表格,用于在其中插入值。在服务表中,我有id和customer_id行,我想在支付表中生成相应的id值。 这是我的服务表
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
这是我的付款添加表单
<form class="form-horizontal" action="<?php echo base_url(); ?>account_control/make_payment/<?php echo $result->code;?>" method="post">
<div class="box-body">
<!-- end -->
<!-- end -->
<!-- end -->
<!-- end -->
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Order ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="order_id" id="order_id" placeholder="" value="<?php echo $result->id;?>">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Customer ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="customer_id" id="customer_id" placeholder="" value="<?php echo $result->customer_id;?>">
</div>
<div class="clearfix"></div>
</div>
<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">Type</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>
<!-- end -->
</div>
<!-- /.box-body -->
<div class="box-footer col-md-8 col-md-offset-2">
<input name="id" type="hidden" value="<?php echo $result->id; ?>">
<button type="submit" class="btn btn-info pull-right" style="margin-left: 17px;">Submit</button>
<button type="submit" class="btn btn-default pull-right">Cancel</button>
</div>
<!-- /.box-footer -->
<div class="clearfix"></div>
</form>
这是我的控制器
public function make_payment($code)
{
$data['active_mn']='';
$data['active_mn']='';
if($code){
$code=$this->uri->segment(3);
$data['result']=$this->Account_model->view_order_id($code);
}
$this->form_validation->set_rules('actual_amount','Amount','required');
if($this->form_validation->run()==true)
{
if($this->Account_model->make_payment())
{
$this->session->set_flashdata('message','updated successfully');
redirect('account_control/view_order');
}
else
{
$this->session->set_flashdata('message','update failed');
redirect('account_control/edit_order');
}
}
$this->load->view('make_payment',$data);
}
这是我的模特
public function make_payment()
{
$paid = $this->input->post('paid_amount');
$total = $this->input->post('total_amount');
$balance = $this->input->post('balance');
$order_id = $this->input->post('order_id');
$customer_id = $this->input->post('customer_id');
$data = array('order_id' => $order_id,
'customer_id' => $customer_id,
'actual_amount'=>$total,
'paid_amount' => $paid,
'balance' => $balance
);
print_r($data);
if($this->db->insert('payment',$data))
{
return TRUE;
}
else
{
return FALSE;
}
}
当我输入数据时,数据没有被插入,而且在order_id和customer_id的位置获得0值