How to change the value in the database at the click of a button?

Prompt, please, as when you press the button to change the value in the database ('users') from the user.

The user has logged on. Got your id. And with it your (game) by "Balance" which is 0. Then he presses the button. And now his account is "Balance: 1".
5e0bf464dd2ec364467449.jpeg
5e0bf5e2b2dc2794140593.jpeg

I was advised to do so:

Php-first get the column value, and then add the desired value to overwrite the result in the column.

$value1=$bd->query("SELECT `balance` FROM `table_name` WHERE `id`='userid'")->fetch_array(MYSQLI_ASSOC);
$value=$value1+$value2//value2 can be any value that you need to add
$bd->query("UPDATE `table_name` SET `balance`='".$value."' WHERE `id`='user_id'");

But to call pressing the button will have to use javascript. Otherwise, no way.

But something what day it is impossible to implement. Help, please.
April 4th 20 at 00:28
3 answers
April 4th 20 at 00:30
Solution
Does

When you click on the button in the browser you cannot change the value in the database.
When you press the button you can only send a request to PHP.
And in PHP you can query the database.
That is two actions, not one. And to fulfill their needs in turn.
That is why you can not. Because you're trying to do two things at once. Do them in turn.
April 4th 20 at 00:32
UPDATE table_name
SET balance = balance + 1
WHERE id=user_id;
April 4th 20 at 00:34
But to call pressing the button will have to use javascript. Otherwise, no way.

So what's the problem? So do it. And you will have implemented change values in the database by pressing a single key. JS for user interaction just there. And PHP to work NOT with the user. Live for centuries in a symbiotic relationship :)

Find more questions by tags AJAXPHP