I solved it with the help from the comments above and using a lot of trial and error, here is the working code:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
//make sure you run this otherwise the $post request wont work!
Then where in the JavaScript function where I wanted to run the code I put:
$.post('register.php', {score: this.score}, function(){}).error(function(){
alert('error... ohh no!');
});
//this runs the php file parsing through the score variable
Here is the PHP code which I then run to add the parsed through variable to the table in the database:
<?php
$score = $_POST['score'];
mysql_connect("localhost", "root", "password");
mysql_select_db("staroids");
mysql_query("INSERT INTO scores (score) VALUES ('$score')");
?>