• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PHP+AS3 Problem

Explorer ,
May 04, 2008 May 04, 2008

Copy link to clipboard

Copied

I am trying to send data (variables) to a php file. I keep getting an error even though I am using the exact method used in Flash Help (something like Using External Data).
TOPICS
ActionScript

Views

952

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2008 May 04, 2008

Copy link to clipboard

Copied

Does it trace...

function done(event:Event) {
----------------------------------------->
trace(event.target.data.writing);
tester.text = event.target.data.writing;
}

what does the data.writing do?




"jishi9" <webforumsuser@macromedia.com> wrote in message
news:fvl0qm$a9c$1@forums.macromedia.com...
>I am trying to send data (variables) to a php file. I keep getting an error
> even though I am using the exact method used in Flash Help (something like
> Using External Data).
>
> //////Actionscript 3 (tester is a dynamic textfield on stage)
>
> var req:URLRequest = new URLRequest();
> req.url = "save.php";
> req.method = URLRequestMethod.POST;
> var vars:URLVariables = new URLVariables();
> vars.Name = "some name";
> vars.Comments = "some comment";
> req.data = vars;
>
> var loader:URLLoader = new URLLoader();
> loader.dataFormat = URLLoaderDataFormat.VARIABLES;
> loader.load(req);
> loader.addEventListener(Event.COMPLETE, done);
>
> function done(event:Event) {
> tester.text = event.target.data.writing;
> }
>
>
>
>
> Error: Error #2101: The String passed to URLVariables.decode() must be a
> URL-encoded query string containing name/value pairs.
> at Error$/throwError()
> at flash.net::URLVariables/decode()
> at flash.net::URLVariables$iinit()
> at flash.net::URLLoader/flash.net:URLLoader::onComplete()
>
>
>
> ////////PHP Code (saves data to a text file)
>
> <?php
> //Capture data from $_POST array
> $name = $_POST['Name'];
> $comments = $_POST['Comments'];
> //Make one big string in a format Flash understand
> $toSave ="Name=$name&Comments=$comments;
> //Open a file in write mode
> $fp = fopen("comments.txt", "w");
> if(fwrite($fp, $toSave)) echo "writing=Ok&";
> else echo "writing=Error&"
> fclose($fp);
> ?>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2008 May 06, 2008

Copy link to clipboard

Copied

It never makes it to the done function. I get the error before after loading the request.

As for the writing variable, it is just a confirmation that the data has been saved.


reply to kglad : as for the php mistake i have corrected it but I still have the same issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2008 May 04, 2008

Copy link to clipboard

Copied

you have, at least, one malformed php line:

$toSave ="Name=$name&Comments=$comments;

should be:

$toSave = "Name=" .$name1. "&Comments=" .$comments;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 06, 2008 May 06, 2008

Copy link to clipboard

Copied

Remove:

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

This may not solve the problem you are having, but I have seen this causing problems before.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2008 May 06, 2008

Copy link to clipboard

Copied

When I remove this line, it seems to send (I get an OK in my textfield) but I don't think the php code correctly receives the data (it expects variables to be sent to it) and I also get an error regarding the writing variable:

ReferenceError: Error #1069: Property writing not found on String and there is no default value.
at this_fla::MainTimeline/done()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()


I think it is necessary to have the DataFormat set to variables in this situation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2008 May 06, 2008

Copy link to clipboard

Copied

Ok I think I understand how I can get this to work. I keep the dataFormat as Text and then I create a new URLVariables which decodes the data received from the php file, which seems to work fine, except for one thing. The data I receive is the actual contents of the php file, not its echo statements. It seems as if the php file is not working.I even changed the php file to simply echo a string, but with no change.

I get this problem both locally and on the server which is php enabled.

Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 07, 2008 May 07, 2008

Copy link to clipboard

Copied

LATEST
Ok I have this code now (I made the php code as simple as possible so that I can trace the source of the problem easily :




////////////AS3

var req:URLRequest = new URLRequest();
req.url = "save.php";
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
req.data = vars;

var loader:URLLoader = new URLLoader();
trace("begin sending...");
try {
loader.load(req);
} catch (error:Object) {
ttrace(error);
}
loader.addEventListener(Event.COMPLETE, done);


function done(event:Event) {
trace(event.target.data);
}

stop();


//////////////PHP Code

<?php
echo "HI";
?>



/////////Output Panel:

begin sending...
<?php



echo "HI";



?>

////////////////////////////////////////////////////////////////////////DONE

Why am I getting the php file back and not 'HI' from the echo statement?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines