Simple Flash AS <-> PHP example

Im trying to get a grip on Flash AS (client-side) and PHP (server-side) interaction.

This Flash ActionScript is supposed to send a variable (myData.ClanName) found in a textbox (TXTBOX_TESTING) to a PHP-script (when a button is pushed):

on(press){
myData = new LoadVars();
myData.ClanName = TXTBOX_TESTING;
myData.send(“http://members.lycos.co.uk/usnswe/contact/contact.php”);
}

Then this PHP-script is supposed to add this varible to a textfile (contact.txt):

<?php
$FileName = “contact.txt”;
$FilePointer = fopen($FileName, “a”);
fwrite($FilePointer, $ClanName); // Dubious Variable
fclose($FilePointer);
?>

Well, I know the PHP-script works, as Ive tried to put plaintext into the “fwrite”-functions second parameter instead of the “$ClanName”-parameter.
That will create/open “contact.txt” and add a line to it.

The problem with Flash AS is:
a) It doesnt seem to call the PHP-script when the button is pushed.
b) I dont know the correct syntax to translate the myData.ClanName - variable (sent from the AS) to a variable that the PHP-script can read.
Above Ive tried “$ClanName” (PHP: 4th line), but that doesnt seem to work.

Any suggestions?

$ClanName should be $_POST[‘ClanName’];

Ok, that should solve problem b) - thanks :slight_smile:

Now onto problem a).
Ive changed the php-file to:

<?php

$FileName = “contact.txt”;
$FilePointer = fopen($FileName, “a”);
fwrite($FilePointer, $_POST[‘ClanName’]);
fclose($FilePointer);

?>

But still the data doesnt seem to be sent from the Flash AS in the first place. Why?

on(press){
myData = new LoadVars();
myData.ClanName = TXTBOX_TESTING;
myData.send(“http://…contact.php”);
}

would myData.ClanName = TXTBOX_TESTING.text do it?

Ok, using “sendAndLoad” instead of “send” with LoadVars-objects got it working. Also, the “POST” method of “sendAndLoad”-function should probably be specified, since the “GET”-method could otherwise be used (which would make the retreival of the “ClanName”-variable in the PHP-code a bit tricky, since it uses “POST”).

on(press){
myData = new LoadVars();
returnData = new LoadVars();
myData.ClanName = TXTBOX_TESTING.text;
myData.sendAndLoad(“http://www.myWebpage.com/contact.php”, returnData, “POST”);
}

Thanks for the help.

LoadVars.send() uses POST by default… i don’t see why would you use sendAndLoad and specify the POST again…

Your right. Some faulty debugging made me draw that premature conclusion. It works fine without.