views:

41

answers:

2

Hi guys, I would like to update a mySQL column,

basically I would like to get a specific user in the DB, and then add the number I have to the number in the DB column.

So say for instance user 12345 has 55 points, and I wanna add 25 points to his score, how would I go about updating the points column to reflect 80?

Thanx in advance!

+4  A: 
UPDATE scoreboard
SET points=points+25
WHERE user=12345
Ignacio Vazquez-Abrams
+1: Give the rest of us a chance, eh? :p
OMG Ponies
Yeah, no kidding.
webbiedave
Probably a noob mistake, but I am using PHP to do the update, and I am getting this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user=12345' at line 1"And here is my code mysql_query("UPDATE scoreboard SET points=points+$points WHERE user=$uid")or die(mysql_error());
Are you sanitizing and validating `$points`? What does it contain?
Ignacio Vazquez-Abrams
I am getting points via $_GET like so $points = $_GET['points'], so no sanitation that I know of.
I have a users table in my database which contains the userId and points columns.
"no sanitation that I know of" FIX THIS. It will bite you in the behind eventually.
Ignacio Vazquez-Abrams
My bad, stupid mistake, the $_GET variable wasn't set! It's working now! Thanx alot for the help! function sanitize($hello){ $hello = strip_tags($hello); $hello = mysql_real_escape_string($hello); return $hello;}, would this be ok?
For the sanitization, sure. Validating that it's an integer will help you catch other problems as well.
Ignacio Vazquez-Abrams
Cool, will implement that! Thanx for the heads up!
+2  A: 
UPDATE scores SET
points = points + 25
WHERE id = 12345;
webbiedave
Thanx for the help!
You're very welcome.
webbiedave