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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.