0

I have two tables named services and payment and two forms for inserting values in to it. When I enter data into services, I am getting two field names id and customer_id and I want to convert those values into 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">&times;</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;
    }
}

I am 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

5
  • why are you using null as a varchar?? Commented Jun 3, 2016 at 6:06
  • if varchar is not null then also the value is not getting in to it Commented Jun 3, 2016 at 6:20
  • <input type="hidden" name="order_id" id="order_id"> value is empty Commented Jun 3, 2016 at 6:53
  • i think your hidden field order_id is not being set....So,check it once Commented Jun 3, 2016 at 6:56
  • I don't understand why you have 4 separate for="inputEmail3", but no element with id="inputEmail3". Thus these are all meaningless declarations. Model methods should not be directly accessing submission data - data should be passed in from the call site. Commented Oct 19 at 9:05

2 Answers 2

1

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">
Sign up to request clarification or add additional context in comments.

1 Comment

yes..the value will not be same for all order_id and customer_id
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.