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!"; } Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/ 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 Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301028 Share on other sites More sharing options...
ryeman98 Posted July 19, 2007 Author Share Posted July 19, 2007 That doesn't work either. Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301905 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..... Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301915 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... Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301919 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.... Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301921 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' Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301925 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. Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301929 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... Link to comment https://forums.phpfreaks.com/topic/60494-solved-quick-help/#findComment-301937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.