Reputation: 509
How would i send values from my javascript game to my php server?
if (!alive) {
if (sendData) {
$.ajax({
type:'GET',
url:'submitscore.php',
data:'?name='+person+'&score='+score,
success:function(data) {
if(data) {
alert("Score Submitted");
} else {
alert("Error - Contact Developer");
}
}
});
sendData = false;
// rest of gameover script
Php code
foreach ($_GET as $key => $value ) {
$value = mysql_real_escape_string($value);
$$key = $value;
}
mysql_query("INSERT INTO score (name,score)VALUES('$name','$score')") or die(mysql_error());
I get no errors from either script and i get a new field in my database but with empty values,
I have checked the variable names of the javascript and they are correct and hold the values.
When i call the php script directly via localhost/submitscore.php?name=name&score=2 the script runs and saves that data
Upvotes: 0
Views: 121
Reputation: 516
I think the data should not be prepended with ?: it should only be name/value pairs.
Upvotes: 1