Hey guys.
I'm having a hard time here figuring out how to subtract two values from the same row in one query.

Here's what I'm trying to do.

$newcredits = $points_me->points - $_POST['amount']-5;
$result = mysql_query("UPDATE `users` SET `points` = '".mysql_real_escape_string($newpoints)."' WHERE `name`='".mysql_real_escape_string($_SESSION['Name'])."'");

As you can see, $_POST is value1 and -5 is value2.

Now instead of subtracting the -5 with the query, it simply doesn't understand it, and of obvious reasons sets the field to '0'.


Thanks in advance.

Welcome Daniello555,

You are updating $newpoints and a subtraction is assigned into $newcredits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.