Hi, sir Update query is not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Hi, sir Update query is not working (/showthread.php?tid=79062) |
Hi, sir Update query is not working - sandeep1992 - 04-15-2021 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); } } } RE: Hi, sir Update query is not working - php_rocs - 04-16-2021 @sandeep1992, We need a little more information. What version of CI are you using? What error messages are you seeing? RE: Hi, sir Update query is working after two days searching And I am using CI 4 - sandeep1992 - 04-16-2021 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); } } RE: Hi, sir Update query is not working - davis.lasis - 04-16-2021 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? |