Hi, sir Update query is not working |
if ($invoice_no != null) {
// echo "This is last invoice number" . $invoice_no; for ($i = 0; $i < count($ar_price); $i++) { $rem_qty = $ar_tqty[$i] - $ar_qty[$i]; if ($rem_qty < 0) { echo "Product Out Of Stock!"; } else { $modelpro = new productModel(); $db = \Config\Database::connect(); $builder = $db->table('product'); //Update Product stock $updateQuantity = [ 'Quantity' => $rem_qty, ]; // if ($modelpro->update($updateQuantity)->where('productName', $ar_pro_name[$i])) { // echo "updated"; // } else { // echo "update query error"; // } $builder->where('productName', $ar_pro_name[$i]); $builder->update($updateQuantity); } } }
@sandeep1992,
We need a little more information. What version of CI are you using? What error messages are you seeing?
if ($invoice_no != null) {
// echo "This is last invoice number" . $invoice_no; for ($i = 0; $i < count($ar_price); $i++) { $rem_qty = $ar_tqty[$i] - $ar_qty[$i]; if ($rem_qty < 0) { echo "Product Out Of Stock!"; } else { $modelpro = new productModel(); $modelpro ->where('productName', $ar_pro_name[$i]) ->set(['Quantity' => $rem_qty]) ->update(); } $modelInvo = new invoiceDetailModel(); $saveInvoiceDetail = [ 'invoice_no' => $invoice_no, 'product_name' => $ar_pro_name[$i], 'price' => $ar_price[$i], 'qty' => $ar_qty[$i], ]; $modelInvo->save($saveInvoiceDetail); } }
by the code and approach - this seems to be done in a controller - just a guess
maybe your `$invoice_id` is 0 maybe your `$invoice_id` is "" last option is most likely as that's how empty input values are posted - as empty strings, but never NULLs Maybe for your build php function empty() could do a magic? |
Welcome Guest, Not a member yet? Register Sign In |