You see here in this code that you’ve added:
$newValue = wallet;
$sql = "UPDATE users SET wallet = wallet + $newValue WHERE user_id = 'id'";
you create a variable called $newValue
. You can tell it’s a variable because it starts with a dollar sign, which is how PHP - all the PHP code you’ve already got - names variables. You then try to assign the value of wallet
to it - but that isn’t a variable, because it doesn’t start with a dollar-sign. It’s not a string either, because it hasn’t got quotation marks - single or double - around it. So PHP assumes it’s a constant, but if you haven’t defined it as such, you should be getting an error message on this line if you have error-reporting enabled, like I said before. If you don’t have it enabled, you should enable it on your development system while you’re developing new code, especially if you’re unfamiliar with the language.
So, where does your value for wallet
come from? If it’s a form input, then you can see how you get all the other form input values, and use the same method to get the wallet value from the form. You must have that correct somewhere, because you said it’s being written into the transactions table correctly at one point.
On the second line of code, you can see how you use a variable name inside a query string, because you use $newValue
correctly - or you would, if it had a value - but it will have, once you’ve corrected the error on the first line. So, you can see what the difference is between a variable inside a query, and a fixed string. You are using a fixed string of id
for your user-id, and you need to use the correct variable instead.
The other issue, of course, is that while you create a query string, you don’t actually execute the query anywhere. So once you’ve corrected the error in line 1 of the code I’ve highlighted, and corrected the incorrect WHERE clause in the second line, you have to then execute the query to make it alter the database.