我需要使用PHP / MySQL保存Flash游戏的高分,但它无法正常工作
以下是代码:
AS3
ActionScript:
var myrequest:URLRequest = new URLRequest("score.php");
myrequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.name = nombrem;
variables.score = puntosJugador;
myrequest.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myrequest);
PHP
//Include database connection details
require_once('config.php');
//Connect to mysql server
$link = mysql_connect([b]**HOST**, **USERNAME**, **PASSWORD**[/b]D);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(**DATABASENA**);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$name = clean($_POST['username']);
$score = clean($_POST['score']);
$currentdate = date("Y/m/d");
//Create INSERT query
$qry = "INSERT INTO highscores(user,time,date) VALUES('$name','$score','$currentdate')";
$result = @mysql_query($qry);
echo "writing=Ok";
exit();
mysql_close();
?>
我在MySQL上创建了一个名为' highscores'名字'用户','时间'和' date'
有什么帮助吗?
答案 0 :(得分:2)
您正在发送“名称”,但试图通过“用户名”获取它($ _POST ['username'])
也做mysql_close();退出之前(); (一般来说,你不需要退出())。