Jump to content

call to a member function ()free error when updating value in database


Go to solution Solved by mac_gyver,

Recommended Posts

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 by SF23103
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.