Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP Update HELP!!!!


ghost's Avatar
0 0

I am trying to update a MySQL database and add a number to an variable that already has an int stored in to for example i ahve 10 and i want to add 10 so it will make 20 when i UPDATE points SET points += 10 FROM users WHERE user_name= $_SESSION['user_name'] it will not update my SQL i was wondering what i was doing wrong.

Also i need some help with then printing off that session variable when i change the number to anything but 0 it does not show the number i use echo $_SESSION['points'];

Please i really would like some help with this

*** also if your intrested in helping develop my webpage let me know http://blackmind.mywebcommunity.org


ghost's Avatar
0 0

i dont think sql supports the += operator so just use

$current_points = mysql_result(mysql_query("SELECT points FROM users WHERE user_name = '" . mysql_real_escape_string($_SESSION["user_name"]) . "'"), 0); $points = $current_points + 10; $update = mysql_query("UPDATE users SET points = $points WHERE user_name = '" . mysql_real_escape_string($_SESSION["user_name"]) . "'");

as to your other problem, I'd have to see more of your code.