I have a function that validates input from database. My question is how to validate the input if the current input is less than value in the database?
the view
<?php echo form_open('order/confirm');?>
<div class="input-control text">
<input type="text" name="paid_value" value="" placeholder=""/>
<button class="btn-clear"></button>
</div>
<?php echo form_close;?>
the model
function payment_validate(){
$oid = $this->uri->segment(3);
$paid = $this->input->post('paid_value');
$this->db->select('*')
->from('order')
->join('payment','payment.order_id = order.order_id')
->where('order.order_id',$oid)
->where('order.total_bill >', $paid);
$query = $this->db->get();
if($query->num_rows() > 0){
return $this->db->last_query(); //$query->result();
}
else{
return array();
}
}
the controller
function confirm(){ // submit form payment
if (!$this->ion_auth->logged_in()){
redirect('auth/login');
}else{
if($this->nekogear->payment_validate()){ // set error message
$data['bill'] = $this->nekogear->payment_validate();
echo "<pre>";
die(print_r($data, TRUE));
//$this->session->set_userdata('refered_from', $_SERVER['HTTP_REFERER']);
//echo "<script language='javascript'>alert('Insufficient fund.');
//window.location='http://localhost/nekogear/index.php/cart/redirects'</script>";
}else{
$data['goto'] = $this->nekogear->confirm_payment();
echo "<pre>";
die(print_r($data, TRUE));
//echo "<script language='javascript'>alert('Accepted.');
//window.location='http://localhost/nekogear'</script>";
}
}
}
if the inserted value is less than the current value, the print_r result is querying correctly less than current value
Array
(
[bill] => SELECT *
FROM (`order`)
WHERE `order`.`order_id` = '52F89602E6E'
AND `order`.`total_bill` > 10000
)
if more than current value
Array
(
[bill] => Array
(
)
)
so my guess something must be off in my if - else controller logic but I can't figure it out why its always skipping this if
if($this->nekogear->payment_validate()){
// some error message here
}
any idea why? thanks.
Solution I added form hidden for total bill into view then call it inside my controller.
$total = $this->input->post('total_bill');
$paid = $this->input->post('paid_value');
if($paid < $total){
// error message
}else{
// success message
}