保存Flash游戏分数PHP / MySQL
发布时间:2020-12-15 07:28:30 所属栏目:百科 来源:网络整理
导读:我需要使用 PHP / MySQL保存Flash游戏的高分,但它不起作用 这是代码: AS3 ActionScript: var myrequest:URLRequest = new URLRequest("score.php");myrequest.method = URLRequestMethod.POST;var variables:URLVariables = new URLVariables();variables.
我需要使用
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’的表,名称为’user’,’time’和’date’ 有什么帮助吗? 解决方法
你正在发送“名称”,但试图通过“用户名”获取它($_POST [‘username’])
也做mysql_close();退出之前(); (通常,顺便说一下,你不需要exit()). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |