如何将javascript变量保存到MYSQL数据库中?特别是我希望在游戏结束时保存游戏的分数。请参阅以下代码:
function lastScore(num){
document.getElementById('lastscore').textContent = num;
}
function saveScore(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","saveScore.php?s="+player.score,false);
xmlhttp.send(null);
document.getElementById("endgame").innerHTML = xmlhttp.responseText;
}
PHP
<?php
include('server.php');
$s = $_GET['s'];
$db = mysqli_connect( ...MY DATA...);
$query = "INSERT INTO scores (name, score) VALUES ('$username' , '$s')";
mysqli_query($db, $query);
?>
你能告诉我什么是错的吗?我该怎么做才能将player.score
作为参数插入到MYSQL数据库中?感谢