Adding numbers to sql

I have a mysql database with column balance. This table is used to store information about the balance of the user account, so how to add numbers to the mysql statement?

that's what i still have

$sql_data = "UPDATE `database1`.`users` SET (`balance`) = '(what to put here?)' WHERE ('" . $mysqlid . "') "; 

so what should I: a) get the current balance using the mysql select query? and b) what I use to add the integer 5 to the column balance, the mysql row is double (16.2)

+4
source share
3 answers

Try the following:

 $bal=100.5; // balance to be add $sql_data = "UPDATE `database1`.`users` SET `balance` = (`balance`+'$bal') WHERE ('" . $mysqlid . "') "; 
+1
source
 $sql_data = "UPDATE `database1`.`users` SET `balance` = MIN(`balance` + 5, (maximum_value_they_can_have)) WHERE ('" . $mysqlid . "') "; 

Edit:

Perhaps you can do a check to check that balance + 5 does not go beyond the balance data type in PHP using something that is unlikely to run into problems like bcmath functions. (Does the math match the given accuracy with string comparison)

+2
source

You can do it:

 $sql_data = "UPDATE `database1`.`users` SET `balance` = (`balance` + [value to be added]) WHERE ('" . $mysqlid . "') "; 
+1
source

All Articles