NOTE: This very quick tutorial assumes you are comfortable using Swish scripting and know how to use MySQL and PHP.

So you've been working hard on your game and you've come to the point where you want to send the players name and score to your web server and store it in your MySQL database using PHP. How would one accomplish this? Good question!

First off, lets start off with some code from Swish:

Code:
name = "SpaceHunter"
highscore = 2300
Here we simply assign the players name and score to the variables name and highscore respectively. Now we just need to send these variables to our web server. Simple enough.

Code:
loadVariables("submitscore.html",'POST');
The LoadVariables function allows us to accomplish this feat. Notice the html file we are referencing, submitscore.html. This file will need to exist on your web server. What were doing here is telling Swish to POST variables name and highscore to the URL submitscore.html.

Now, lets look at the contents of submitscore.html:

Code:
$name = $HTTP_POST_VARS['name'];
$score = $HTTP_POST_VARS['highscore'];

$sql = "insert into lm_highscore
        (name, highscore)
        values
        ('$name', '$highscore')";  // Create an SQL statement to insert name and highscore to our table.
        
$result = mysql_query($sql);  // Make it happen.
A few things to note here:

$name is the name that we assigned SpaceHunter in our Swish script.
$highscore contains the value 2300 that we also assigned in our Swish script.
Lm_highscore is my highscore table that I created in my MySQL database.

You could easily use echo to print the players name and score if you wish to test your setup between Swish and your web server.

Code:
echo $name;
echo $highscore;
You can see how the score mechanism is used in my latest game Lunar Mission! Notice the far right of the game you will see my All-Time Top 25 High Scores. The score table elements are comprised from this tutorial.

I know..I know...It's quick and dirty. But if your eager to get your score system to work for you this tutorial will get you started in the right direction.

Enjoy

-SpaceHunter