PDA

View Full Version : php http_build_query


jimathy
09-28-2008, 06:14 PM
I am trying to send variables to flash with the php http_build_query function. The problem I am having is that only the first variable is defined the rest come back as undefined.

My actionscript 3 code is as follows:

var reqURL:URLRequest = new URLRequest("http://localhost/Fetch/ExtVarsTest.php?randomVar="+Math.random());
var ldr:URLLoader = new URLLoader();
ldr.load(reqURL);
ldr.dataFormat = URLLoaderDataFormat.VARIABLES;
ldr.addEventListener(Event.COMPLETE, handleComplete);
function handleComplete(event:Event):void {
var ldr:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(ldr.data);
var str:String = "The Data: "+ "\n" + vars.username+ "\n" + vars.email;
tf.text = str;
}

The php code is:

$returnVars = array();
$returnVars['username'] = "Any User";
$returnVars['email'] = "validmail@mail.com";
$returnString = http_build_query($returnVars);
echo $returnString;

I am runing php version 5.2.4. I am not sure why it doesn't work anyone have any idea.

If I format the return string from php as I have always done as follows
echo "username=Any User&email=validmail@mail.com"
Everything works fine. I am wondering why the http_build_query doesn't work. More out of interest and fustration. I have seen examples sites saying it works fine but I can't get it to work aaaaaaaaaah please tell me why someone

In advance thanks for the help.

Jim

bowljoman
09-28-2008, 07:19 PM
forget about http_build_query()



$row=mysql_fetch_object($res);
$ret=Array(
"username"=>$row->username,
"lastlocation" =>$row->lastlocation,
"publickey" =>$row->publickey
);
return $ret;