Adding 10 percent to a database value

Brunei Darussalam
Topics: 2
Posts: 5
Rep: 0
hey i use this in sql

UPDATE userStats SET US_money = US_money + 10

to give all users 10 more money :P
but how do i do it if i want to add 5% to the value

also if money on my acc is $4,555 and i want to add 5% = 4555 + 5% = 4782

How can i do it?

File: 5percent.php
<?
$db_host = "localhost";
$db_user = "root";
$db_pass = "1234";
$db_name = "root";
$connect = @mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db($db_name);

//here i want the query to add 5 percent
$query = "UPDATE userStats SET US_money = US_money + 5";
mysql_query($query);
?>

when i go to localhost/5percent.php iwant it toadd 5% to all users money how can i do it?


hope you understand and can help me :)
2014-04-20 16:52:04
Chris Day
Topics: 9
Posts: 71
Rep: 32
the folowing script will add 10% extra cash to every player just change $perc to the value you want

<?php

include 'dbconn.php';

$perc = 10;
$perc = ($perc/100)+1;

$db->query("UPDATE tbl userStats SET US_money = US_money*".$perc);

?>
2014-04-20 17:18:45
kollegah
Topics: 11
Posts: 29
Rep: 10
<?
$db_host = "localhost";
$db_user = "root";
$db_pass = "1234";
$db_name = "root";
$connect = @mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db($db_name);

//just change the "5" to any number. 5 = 5% 45= 45%
$query = "UPDATE userStats SET US_money = US_money + US_money / 100 * 5";
mysql_query($query);
?>
will add 5% but you can use the script chris gived you :)

2014-04-20 17:29:04
Chris Day
Topics: 9
Posts: 71
Rep: 32
sorry my script broke you need
<?php

include 'dbconn.php';

$perc = 10;

$perc = ($perc/100)+1;

$db->query("UPDATE userStats SET US_money = US_money*".$perc);

?>


Rather then use the mysql_* functions i would advise you use PDO as mysql* is being deprecated in later versions of PHP
2014-04-20 17:45:32