whiskedaway Posted November 18, 2009 Share Posted November 18, 2009 I'm having a problem with my second query. I've included the PHP around it as it might help to see what I'm trying to do. $sql = "SELECT quantity, sku FROM ItemsOrdered WHERE orderID = '$_POST[orderID]'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query 1."); $rowname = mysqli_fetch_assoc($result); extract ($rowname); $sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity') WHERE sku = '$sku'"; $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute query 2."); Can someone see what the problem is? I think it has to do with the quantity = (quantity + '$quantity') part. Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/ Share on other sites More sharing options...
rajivgonsalves Posted November 18, 2009 Share Posted November 18, 2009 what exactly is the problem, the query should be $sql2 = "UPDATE Stock SET quantity = quantity + $quantity WHERE sku = '$sku'"; Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-959773 Share on other sites More sharing options...
whiskedaway Posted November 19, 2009 Author Share Posted November 19, 2009 I keep getting the error "Couldn't execute query 2." which is why I think there's a problem with my query 2 syntax. I've tried these four changes to the query: $sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity') WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = quantity + '$quantity' WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = quantity + $quantity WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = (quantity + $quantity) WHERE sku = '$sku'"; It just won't work at all. The only other thing I can think of is that maybe the PHP before it is wrong, but I can't see an error in that either. Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960704 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 please change this $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute query 2."); to $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute query 2:".mysql_error()); for a better error description once you done that you should have the exact error and it will enable us to debug your code Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960834 Share on other sites More sharing options...
whiskedaway Posted November 19, 2009 Author Share Posted November 19, 2009 Unfortunately, that hasn't yielded any results: Couldn't execute query 2: If you want to have a look at it yourself, it's up at http://www.caitlin-helbig.com/adelaidebooks/receipt.php and you can use an orderID of 00000001. Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960875 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 actually thats because of my faulty code it should have been mysqli_error() instead of mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960878 Share on other sites More sharing options...
whiskedaway Posted November 19, 2009 Author Share Posted November 19, 2009 Oh, I didn't even notice that. Here's the output: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/nabira/chelbig/adelaidebooks/receipt.php on line 23 Couldn't execute query 2. Line 23 is: or die ("Couldn't execute query 2.".mysqli_error()); Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960881 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 hmm.. Yeah you will have to specify your link identifyer as a paramater Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960884 Share on other sites More sharing options...
whiskedaway Posted November 19, 2009 Author Share Posted November 19, 2009 Sorry, I don't get what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960887 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 it should have been mysqli_error($cxn) Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960888 Share on other sites More sharing options...
whiskedaway Posted November 19, 2009 Author Share Posted November 19, 2009 Oh gotcha. Here's the new error message: Couldn't execute query 2. Unknown column 'quantity' in 'field list'. And I think I just figured it out myself. The column is named quantity in ItemsOrdered, but it's quantityOnHand in Stock. Gah. Thanks so much for your help, I can't believe I made such a stupid error. Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960892 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 Well we all make these mistakes, you can save alot of time if you have more descriptive error messages in your code that would pinpoint the problem right away Quote Link to comment https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960895 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.