Creating your own Leaderboard / Highscores Easy and Free (PHP & MySQL) [UPDATED 2020]

  • 69 favourites


Attached Files

The following files have been attached to this tutorial:



Download now 180.37 KB


31,756 visits, 86,667 views



This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Creating a Database (MySQL)

We are going to create a database. A database is an organized collection of data. This is very helpful to store highscores, usernames and many other information useful in your games. MySQL is a powerful language to create and manage databases.

Log in to your account, access your Dashboard ("Manage Website"). In Tools go to Database Manager and create a New Database.

In the new window, you will create a database: with a database user and a database password. You can fill this data as you want, but I recommend you to copy the same info as shown here (so you can follow better the tutorial then you can change it later):

-database = db

-user = user

-password = ******** (whatever you want but don't forget it. You'll need this in a few minutes)

Notice that your complete database name is not 'db', it is something like id13353839_db. Also, your username is not 'user', it's again id13353839_user.

Congratulations, you have created your first database!

Creating a Database Table

Databases are a collection of data organized in tables. Every table saves data about something, like data about "users", data about "scores", data about "friends", etc...

Our recently created database is right now empty, we have to create our first table. Let's see how to create a table...

Go back to your Control Panel and enter phpMyAdmin.

A new phpMyAdmin window will open up. We can see that there are no tables created yet. But we are about to add the first one.

Click the tab called SQL to write SQL code. Paste the following code and click "GO":


Now a new table has been created. This code tells MySQL to create a table with three values: ID, NAME and SCORE. So for every user sending a score to the database, we will store his name and his score.

Notice how on the left side now we have a table: 'scores'. We can also see the structure of this table...


We have now our table ready so we can start writing and reading scores from PHP files!

(Manually) Inserting your first row

Tables are composed by 'rows'. Every row has information about the same subject. In the 'scores' table, every row must contain 3 fields: id, name and score.

For example one row is (ignore id): "JohnSmith 815"

We are going to manually add a row for testing purposes. Click the Insert tab and add the following information to the new row, then click the "Go" button:

If you click the Browse tab you can see all the information stored in this table. In other words: you can read all the scores submitted !!!

We have manually added some data to our table. Now we will see how to write and read scores from PHP files. Read on...


  • Order by
Want to leave a comment? Login or Register an account!
  • [FIXED] The scripts save/get should be updated according to the latest PHP formatting rules. After fiddling after a bit I found that in the save.php you should remove the "id" parts when inserting the score.

  • Great tutorial for a refresher. Ive just finished reading through the tutorial and will soon be implementing the PHP.

  • Thanks for this super clear tutorial! I like your idea about separating the scores by 'level' or by 'difficulty' (easy, medium, hard). Do you have a tutorial for this? Thanks alot!!!!

    • First, your scores table must have a new column. So you have: name, score AND level/difficulty.

      Then, when submitting score to savescores.php, you already sent name & score. Now you must also add the new variable: level/difficulty.

      Last, when getting scores with getscores.php, let's say you will read only scores for level 2 or difficulty easy.

      You can send a variable level/difficulty from the game to getscores.php. Edit the getscores.php PHP file to read from the Database only the scores with the requested level/difficulty.

  • hello, I have successfully created Hiscore with this tutorial. But I have a problem when I want to update the database or delete it.

    Can you please help how to update and delete the database?

  • Hi! Thanks a lot for this tutorial and for giving us the example projects and folders! This is really what users want!

    Could you please explain how could I improve/edit the design of the leaderboard tables? What would be the method? I there a way I can create the design on a software like Dreamweaver and have this php/mysql leaderboard implemented? Ou maybe even edit the design as a page/post on Wordpress?

    Lastly, would you be wiling to help me doing this for a work project of mine? Off course I'll be glad to pay something.

    All the best,

  • Load more comments (92 replies)