Jump to content

[SOLVED] Quick help?


ryeman98

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.