PDA

View Full Version : Need help connecting to PHP



Sketchbookshark
July 14th, 2009, 12:00 PM
Hi everyone,

Iam using CS4, AS3.0. And I am trying to connect my swf to PHP with not much luck. Instead of receiving what is in the print command I get the whole php-document back. It seems PHP is not executing at all. Can anybody help. (PS.: I don;t know much about php at all)

The following is just a very reduced random example that I am using to figure this out. It has no purpose, but to serve me as a test run, and that doesn't work either.

Here is my php test code:


<?php>
$name=&_POST['user'];
$alter=&_POST['age'];

$userInf="$name";
$userInf .="idNum=1005";

if ($alter>18)
{
print $userInf;
}

?>Here is my Actionscript Code (minus the texfield creation and all that):


function goPHP() {
var phpFile:String="http://localhost/geloest.php";//
var variables:URLVariables=new URLVariables ;
variables.user="Markus";
variables.age=36;

var urlRequest:URLRequest=new URLRequest(phpFile);
urlRequest.data=variables;
urlRequest.method=URLRequestMethod.POST;

var testloader:URLLoader=new URLLoader();
testloader.addEventListener(Event.COMPLETE,receive MSG);
testloader.load(urlRequest);

}
function receiveMSG(e:Event):void{
var urlLoader:URLLoader = URLLoader(e.target);
var args:URLVariables =new URLVariables(urlLoader.data);
generalTxtBox.text=args.toString();
post();
}

function post(){
addChild(generalTxtBox);
}I get the following result in my text box:

%3C%3Fphp%3E%0D%0A%24name=&%5FPOST%5B%27user%27%5D%3B%0D%0A%24alter=&%5FPOST%5B%27age%27%5D%3B%0D%0A%0D%0A%24userInf=%2 2%24name%22%3B%0D%0A%24userInf%20%2E%3D%22idNum%3D 1005%22%3B%0D%0A%0D%0Aif%20%28%24alter%3E18%29%0D% 0A%7B%0D%0Aprint%20%24userInf%3B%0D%0A%7D%0D%0A%0D %0A%3F%3E

When I change

generalTxtBox.text=args.toString();

to

generalTxtBox.text=args.userInf.idNum;

the output window states that it is null


Pleeeeease help.

dmennenoh
July 14th, 2009, 03:17 PM
Couple things.

It is $_POST not &_POST

I am not sure but I would think you need an ampersand between returned variables:

$userInf="$name";
$userInf .="&idNum=1005";

print is probably okay, but I would always use echo

I am not sure with AS3 but it used to be that when testing from the Flash IDE you would need to use $_GET or $_REQUEST in PHP, as Flash would send using GET, regardless if you told it to use POST. That may have changed though with AS3. I haven't used anything but remoting for a long time though...

Sketchbookshark
July 14th, 2009, 06:17 PM
Thank you dmennenoh. The $ and & totally fixed it. It seems that post works in AS3.0

Thank you!