Question

I have a query like this inside for loop in codeigniter. But it executes with another values. Not with the values getting through POST method

$j = $_POST['hidden'];
    $inv_id = $_POST['invoice_id'];
    $sum = '';
    for($i = 1; $i <= $j; $i++){
    $wh_quantity1 = $_POST['quantity'.$i];
    //print_r($wh_quantity1);

    if($wh_quantity1 ==''){

        $wh_quantity = 0;
    }
    else{
        $wh_quantity = $wh_quantity1;
    }
    $query = "UPDATE  tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $wh_quantity WHERE invoice_id = '$inv_id'";
    $this->db->query($query);
    $sum += $wh_quantity; 

    }

Why it is like that. It always updates with greater values than POST value

No correct solution

OTHER TIPS

Put this in .htaccess file

RewriteEngine On
RewriteRule ^ http://example.com/international/university-english-access-course$ http://example.com/website/page/english-access [R=301,L]

Try this in case your dont have all post index

    $j = $this->input->post('hidden');
    $inv_id = $this->input->post('invoice_id');
    $sum = 0;
    for ($i = 1; $i <= $j; $i++) {
        $wh_quantity = (int) $this->input->post('quantity' . $i);
        $sum += $wh_quantity;
    }

    $query = "UPDATE  tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $sum WHERE invoice_id = '$inv_id'";
    $this->db->query($query);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top