vincej Posted May 4, 2012 Share Posted May 4, 2012 Hi _ this is for me a mystery and I am pulling my hair out ! I have a column in a table which for some bizarre reason will not consistently update. Here are 2 rows from the table. Note the column 'Picking' - it is a 10 digit VARCHAR. When I run my code the other fields will happily update but SOMETIMES A PICKING WILL REFUSE as you can see in this example. Or just as likely it will update on the second row but refuse the first row. Or even visa versa. It's driving me nuts ! I THANK YOU if you can spot what is going on !!! Many Thanks ! ID OrderID CustomerID ProdID Prodname Price Quantity Pricelb Weight OrderValue Picking Sale 33 JAC8846 5 17 Ribs Large 60.00 1 5.00 5.00 25.00 open open 34 JAC8846 5 28 Chicken 15.00 1 0.00 0.00 15.00 finished open Here is the code which creates the variables. You will notice that there are few statements in there for testing purposes where I echo stuff out. function finishedorder(){ $prodname = $_POST['prodname']; $prodid =$_POST['prodid']; $quantity = $_POST['quantity']; $pricelb = $_POST['pricelb']; $customerid = $_POST['customerid']; $price = $_POST['price']; $orderid = $_POST['orderid']; $weight = $_POST['weight']; echo "line 191 Weight"; print_r ($_POST['weight']); echo"<br/>"; echo "line 192 PriceLB"; print_r ($_POST['pricelb']); echo "<br/>"; echo "line 193 Price"; print_r ($_POST['price']); echo "<br/>"; echo "line 193 ProdID"; print_r ($_POST['prodid']); echo "<br/>"; if (!isset( $_POST['weight'])){ $weight = 0; } else $weight = $_POST['weight']; $numloops = count($_POST['prodid']); for ($i = 0; $i < $numloops ; $i++) { // <======= FOR LOOP if ($pricelb[$i] > 0 ){ $pricelb = $pricelb[$i]; $weight = $weight[$i]; $ordervalue = $pricelb * $weight; echo '$ordervalue1 ' .$ordervalue;echo "<br/>"; echo 'Weight1 '. $weight[$i];echo "<br/>";} if ($pricelb[$i] < 1 ){ $ordervalue = $price[$i]; $weight[$i] = 0; echo '$ordervalue2 ' .$ordervalue;echo "<br/>"; echo 'Weight2 '.$weight[$i];echo "<br/>"; } $sql =" // <======= SQL UPDATE confirmedorder SET weight='$weight[$i]' , ordervalue='$ordervalue', confirmedorder.picking = 'finished', confirmedorder.sale = 'open' WHERE prodID = '$prodid[$i]' AND OrderID = '$orderid[$i]' ; "; $this->db->query($sql); } } here are the reuslts of the echoed out POST arrays from the top mwith corresponding line numbers line 191 WeightArray ( [0] => 5 ) line 192 PriceLBArray ( [0] => 5.00 [1] => 0.00 ) line 193 PriceArray ( [0] => 60.00 [1] => 15.00 ) line 193 ProdIDArray ( [0] => 17 [1] => 28 ) $ordervalue1 25 Weight1 5 $ordervalue2 15.00 Weight2 0 Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 4, 2012 Share Posted May 4, 2012 in the same way that you are echoing the other variables (well done)... echo your $_POST['orderid'] and check the content... also you can echo your $sql query before to execute it and validate if you are getting what you are expecting Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.