Reputation: 805
Here am having two tables named services and payment and am having two forms for inserting values in to it..when i enter data in to services there am getting two rows names id and customer_id and i want to generate those values in to payment table while adding to the corresponding id.. This is my services table..
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
This is my payment table
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
This my view page
<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>
My controller looks like this..
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');
}
My model looks like this
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;
}
}
iam getting an error like this
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
This is my output view from the makep payment below action displays the modal
S.No Order # Date Particulars Serial/IME No Complaints Action
1 ORD00027 06/07/2016 led 11 sedsdf make payment
2 ORD00026 06/13/2016 cvbcv 5 tgtdfgfg make payment
the last row i inserted in the payment table is the value i assumed that i should have to get
Upvotes: 0
Views: 57
Reputation: 12085
In your form filed order_id,customer_id hidden filed missing value
attribute
example:
<input type="hidden" name="order_id" value="12" id="order_id">
<input type="hidden" name="customer_id" value="454" id="customer_id">
Upvotes: 1
Reputation: 664
If you getting Column 'order_id' cannot be null
means that your order_id
is not posted or if is posted then it is null.
please check you are getting your order_id
during the insert time or not.
Upvotes: 0