Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:48:55+00:00 2026-05-24T02:48:55+00:00

I’ve created a little weekly trivia game for my website. Basically its five questions,

  • 0

I’ve created a little weekly trivia game for my website. Basically its five questions, then at the end the user can add their score to a scoreboard.

The problem is that I want the scores to carry from week to week and cumulate. So let’s say you got 4 points one week, then 5 points the next. I want the scoreboard to reflect you have 9 points.

So I created a small form with an i
nvisible field that has the users score, a field for the username, and a field for the e-mail address. Next week, when the user takes the quiz again, I want their score to be updated if the username and e-mail match a record in the database. If no record does match, I want an entry to be created.

Here’s the script I came up with, however, it doesn’t work (which doesn’t surprise me, I’m pretty new to PHP/MySQL)

$name = $_POST['name']; //The Username
$score = $_POST['submitscore']; //The users score (0-5)
$email = $_POST['email'];//Users email address
$date = date("F j, Y, g:i a");//The date and time

if($name != '') {
    $qry = "SELECT * FROM scoreboard WHERE name='$name'";
    $result = mysql_query($qry);
    if($result) {
        if(mysql_num_rows($result) > 0) {
        $sum = ($row['SUM(score)']+$score);
        "UPDATE scoreboard SET score = '$sum' WHERE name = '$name'";
        }    
        else    
    $q = mysql_query("INSERT INTO scoreboard (`name`, `email`, `date`, `score`) VALUES ('$name', '$email', '$date', '$score');");
        @mysql_free_result($result);
    }
    else {
        die("Query failed");
    }
}

My table scoreboard looks like this

id……..name……..email………..date………..score

1……..J.Doe…..j.doe@xyz.com…..7/27/11………4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:48:56+00:00Added an answer on May 24, 2026 at 2:48 am

    You’re looking for INSERT... ON DUPLICATE KEY syntax

    "INSERT INTO scoreboard (`name`, `email`, `date`, `score`) ".
       " VALUES ('$name', '$email', '$date', '$score') ".
    "ON DUPLICATE KEY UPDATE `score` = $sum";
    

    Aside:

    Use mysql_real_escape_string!

    $name = mysql_real_escape_string( $_POST['name'] );
    $score = mysql_real_escape_string( $_POST['submitscore'] );
    $email = mysql_real_escape_string( $_POST['email'] );
    $date = date("F j, Y, g:i a");//The date and time
    

    EDIT

    First, this doesn’t really work unless you have a column SUM(SCORE):

    $sum = ($row['SUM(score)']+$score);
    

    If you want the sum of a column, you need to put that in the MySQL query directly. If you just want the score for that row, however, you can use $row['score']. If you need to add to an existing score you don’t need to select for the value (thanks to a1ex07 for pointing this out)

    ON DUPLICATE KEY UPDATE `score` = $score + score
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on this website (http://www.jowannes.com/thomasschoof/flash/LauraBarsby.html) and I created a little gallery. When
I'm having problem with my application on iPhone 3GS. I've created a little game,
i have created little search method. The problem that its hard to read it
I have created a little password generation script. I'm curious to what improvements can
As you can see below I have created a little program to concatenate 2
I created a little web spider in Python which I'm using to collect URLs.
Lets say you created a little Java Desktop app with a jar and some
Hi I have created a little application to move some files around and put
I've just created a little app that programmatically compiles code using the C# Compiler,
Got a strange problem created a little stored proc which need to execute a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.