ryeman98 Posted July 18, 2007 Share Posted July 18, 2007 I'm trying to add a score from a game that is sent through a form, using the post method. How can I make it so that $score is being added on to the points in the database? $score = $_POST['score']; $name = $_POST['name']; if ($_SESSION['username']) { $username = $_SESSION['username']; $addpoints = mysql_query("UPDATE users SET points=points+{$score} WHERE username='$username'"); } $insert_score = mysql_query("INSERT INTO rps (name, score) VALUES ('$name', '$score')"); echo "Your score has been submitted. Go <a href='scores.php?page=rps'>here</a> to view the high score table!"; } Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 18, 2007 Share Posted July 18, 2007 I think you need to change UPDATE users SET points=points+{$score} WHERE username='$username' to: UPDATE users SET points=(points+$score) WHERE username='$username' that should work Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 19, 2007 Author Share Posted July 19, 2007 That doesn't work either. Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 think u nid to query the current points first before updating.... try ds.... $score = $_POST['score']; $name = $_POST['name']; if ($_SESSION['username']) { $username = $_SESSION['username']; $points = mysql_query("select points from users where username='$username' "); $user_data = mysql_fetch_row($points); $user_points = $user_data['points'] + $score; $addpoints = mysql_query("UPDATE users SET points=$user_points WHERE username='$username'"); } $insert_score = mysql_query("INSERT INTO rps (name, score) VALUES ('$name', '$score')"); echo "Your score has been submitted. Go <a href='scores.php?page=rps'>here</a> to view the high score table!"; } not sure bwt ds....just try..... Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 19, 2007 Author Share Posted July 19, 2007 You don't /need/ to. With my other query's, on the site, I just do points=points+10 or something like that... Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 owk....maybe just an error in ur syntax.... Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 bwt ds .... $score = intval($_POST['score']); UPDATE users SET points=(points+$score) WHERE username='$username' Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 19, 2007 Author Share Posted July 19, 2007 Nevermind, I fixed it. $score = intval($_POST['score']); UPDATE users SET points=(points+$score) WHERE username='$username' Why do that? You don't have to put 'intval' in there. Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 how did u solve it pls show the code for me to learn also... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.