The idea of the task is to allow the user to add and withdraw "money" to and from their account. The problem is I can add money, but I can't withdraw it
$funds = $_POST['funds'];
$withdraw_or_add = $_POST['list'];
if($withdraw_or_add == "add")
{
$sql = "UPDATE users SET userFunds = '".$funds."' WHERE userId = 1";
}
else
{
$info = mysql_query("SELECT * FROM users WHERE userId = '1'");
$info = mysql_fetch_assoc($info);
$new_fund = $info['userFunds'] - $funds;
$sql = "UPDATE users SET userFunds = '".$new_fund."' WHERE userId = 1";
}
mysql_select_db('details_db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully
";
mysql_close($conn);
So for example, let's say $fund = 5
and $info['userFunds'] = 20
then the variable $new_fund
should be 15
. But instead it equals -5
. If anyone can help it would be much appreciated.