SF23103 Posted December 15, 2015 Share Posted December 15, 2015 (edited) I am trying to add a query to my script that updates a value in my database by subtracting "1". When I run the query, I get "Fatal error: Call to a member function free() on boolean in ../path/to/my/script" $sql = "UPDATE table_5 SET chairs = chairs - 1 WHERE chairs > 0 AND chair_model = 'model_33'"; Any idea what I'm doing wrong? Table 5: Chairs | Model Number | 22 | model_33 44 | model_44 Edited December 15, 2015 by SF23103 Quote Link to comment https://forums.phpfreaks.com/topic/299772-call-to-a-member-function-free-error-when-updating-value-in-database/ Share on other sites More sharing options...
Solution mac_gyver Posted December 15, 2015 Solution Share Posted December 15, 2015 UPDATE queries don't return a result. calling the ->free() method after running an UPDATE query makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/299772-call-to-a-member-function-free-error-when-updating-value-in-database/#findComment-1528027 Share on other sites More sharing options...
SF23103 Posted December 15, 2015 Author Share Posted December 15, 2015 That's it, not sure why I had that in there. Thanks! Now I have to figure out why the number is going down by two and not one! Quote Link to comment https://forums.phpfreaks.com/topic/299772-call-to-a-member-function-free-error-when-updating-value-in-database/#findComment-1528028 Share on other sites More sharing options...
mac_gyver Posted December 16, 2015 Share Posted December 16, 2015 Now I have to figure out why the number is going down by two and not one! browsers have a habit of requesting pages twice, for several different reasons. you could also have have an error in some of your client side code (submitting a form via ajax and not stopping the browser from submitting it as well) or server side code that's causing it. in any case, you should not be modifying a count in a database column to track quantities of things. you should add a record to a database table for each 'transaction' that adds or subtracts a quantity, like what your bank or credit card company does. this record would would have columns for who (a user_id) caused the change in the quantity, the item_id, the quantity - a positive or negative value, a datatime when the records was inserted, and a status/memo column to record the type of transaction or a comment about the transaction. the initial quantity on hand would also be entered by inserting a row in the table. to get the quantity at any point in time, you would just SUM() the quantity column value for any item_id. Quote Link to comment https://forums.phpfreaks.com/topic/299772-call-to-a-member-function-free-error-when-updating-value-in-database/#findComment-1528029 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.