php - remove amount from price then insert new price


So i have a question. I have no idea how i need to insert a search in google for it so i'm going to ask it here.

I have like 50.00 euro. in mysql table it is showed as

 Id | Username | Balance
 1  | Kev      | 50.00

Now when i buy something that is worth like lets say 5.00 euro it would be 50.00 - 5.00 = 45.00 euro left on balance

 Id | Username | Balance
 1  | Kev      | 45.00

Now my question is. How do i do this with a simply get old balance then insert the new balance into the table? Also i'm using PDO

Sorry for my nooby question but i have no idea how to insert this into a search in google.





You can update a row by setting the column equal to the current column value minus (or plus) another value

UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Username`='Kev' 


UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Id`=1

People are also looking for solutions to the problem: php - rand() to slelect array elements


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.