I am working on an online game in Flash AS3 and utilizing a PHP server with mySQL database. I am manipulating the data in mySQL database using PHP and when I request the PHP file in a browser straightly from 'localhost/php/file.php'
, the database changes perfectly. I have the following AS3 code:
public function getSite(string):Boolean{
var phpVars:URLVariables = new URLVariables();
var t:Boolean = false;
/*
we use the URLRequest method to get the address of our php file and attach the php vars.
*/
var urlRequest:URLRequest = new URLRequest(string);
/*
the POST method is used here so we can use php's $_POST function in order to recieve our php variables.
*/
urlRequest.method = URLRequestMethod.POST;
/*
this attaches our php variables to the url request
*/
urlRequest.data = phpVars;
/*
we use the URLLoader class to send the request URLVariables to the php file
*/
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, check(t));
t = check(t);
/*
runs the function once the php file has spoken to flash
*/
/*
we send the request to the php file
*/
urlLoader.load(urlRequest)
return t;
}
function check(t:Boolean):Function{
return function (event:Event):Boolean{
trace(event.target.data.checkResult);
if(event.target.data.checkResult == "Good"){
t = true;
} else {
t = false;
}
return t;
}
}
Now from here, my "trace
" shows that the URL is loaded and the output is "Good"
, however the database values does not change. This is the PHP file:
<?php
/*
connect to our database
*/
include_once "connect.php";
$sql = "UPDATE accounts SET PlayersOnline = accounts.PlayersOnline + 1";
$query = mysql_query($sql) or exit("checkResult=Bad");
exit("checkResult=Good");
?>
When I go to 'localhost/php/gameSearch.php'
in my web browser the database changes, and I am wondering what the problem is.