Save Flash Games Score PHP / MySQL

I need to save Flash game records using PHP / MySQL, but it does not work

Here is the code:

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(); ?> 

and I created a table in MySQL named "records" with the names "user", "time" and "date"

any help please?

+5
source share
1 answer

you send "name" but try to get it by "username" ($ _POST ['username'])

also does mysql_close (); before leaving(); (in general, you don't need exit (), by the way).

+2
source

Source: https://habr.com/ru/post/1208504/


All Articles