I am currently working on an online connect four game where the state of the game needs to be updated after ever move. i’ve had no problems sending variables from a php script to flash but i’m having difficultly sending variables from flash to php when trying to update a database. i am getting this error message:
The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
To try an understand the process and figure out what i am doing wrong i’ve stripped down both my actionscript and php files to the bare minimum but still it wont seem to work. here is my actionscript:
var game_id:String = "1";
var postURL:String = "updateMoveScript.php";
var variables:URLVariables = new URLVariables();
variables.game_id = game_id;
var urlRequest:URLRequest = new URLRequest(postURL);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, sendHandler);
loader.load(urlRequest);
function sendHandler(evt:Event):void {
var loader:URLLoader = URLLoader(evt.target);
var variables:URLVariables = new URLVariables(loader.data);
}
and here is my php script:
<?php
$connection = mysql_connect($host, $username, $password);
$select_db = mysql_select_db($database);
//posting game info
$game_id = $_POST['game_id'];
$query = "UPDATE games SET red_state='1' WHERE game_id='$game_id'";
mysql_query($query);
?>
i know the php query is fine as i’ve tested it by changing the $game_id variable to the value i want to send.
i’ve tried changing urldataformat from variables to text and also messed about with changing post and get and about every different possible combinations of doing this but with no joy.
i’ve consulted 3 books and read about 700 other forum posts with people having the same problem but can’t find a solution. this is REALLY holding me back and would really appreciate someone pointing out to me where i am going wrong. i know it’s going to be a simple mistake, it always is:)
cheers elliott