Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Supporting Technologies > Server-Side Scripting

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 06-06-2003, 08:40 AM   #1
simontheak
Simon
 
simontheak's Avatar
 
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
Default A couple more newbie PHP questions

Ok - so I've got the hang of passing variables out of a PHP script and into my Flash interface (thanks black!), but I now seem to be having a problem getting my variables out of Flash and in to the script in the first place.

The thing is, the PHP script doesn't seem to be recognising the variables I'm sending it. I've tried two different examples (one of which was a tut file sent with the book I'm reading) and in both cases the variable I'm sending the PHP script is empty by the time it gets there. Having said that though, the script returns a variable nevertheless. I'd think it was something to do with my coding, if it wasn't for the fact that the example I downloaded from the Friends of Ed website behaved exactly the same way which is too much of a coincidence

Which leads me to my first question:

1. Do I need to edit the permissions of a PHP file like I would do a Perl script? Is this why my variables are not being accessed by the script? And if I don't, has anyone got any other idea why my variables are getting lost somewhere between Flash and my script?

2. On a totally different topic all together, how do I get Arrays out of my PHP script and into an Array in Flash?

The first question is the on that's really frustrating me at the moment - I guess the second one is just the icing on the cake.

Any ideas anyone has got would be really useful!

Thanks alot
__________________
"That could be anybody's ass" - Mayor Quimby
simontheak is offline   Reply With Quote
Old 06-06-2003, 12:18 PM   #2
Caimin
Senior Member
 
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
Default

No, you don't need to set permissions for PHP files to run.

What code are you using to send your variables to PHP?
__________________
Caimin Jones
Freelance web, flash + games developer
Caimin is offline   Reply With Quote
Old 06-06-2003, 01:42 PM   #3
simontheak
Simon
 
simontheak's Avatar
 
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
Default

Hi Caiman,

I'm using Flash MX, but the book I'm reading is for Flash 5 so I'm using the following code on a button:
ActionScript Code:
on(release){ loadVariables("test.php", this, "POST"); }

The button is on the main timeline, along with an input text field and a dynamic one which have their variable values named correctly.
__________________
"That could be anybody's ass" - Mayor Quimby
simontheak is offline   Reply With Quote
Old 06-06-2003, 05:07 PM   #4
Caimin
Senior Member
 
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
Default

Ok, you said "in both cases the variable I'm sending the PHP script is empty by the time it gets there. Having said that though, the script returns a variable nevertheless".

How do you know your variables are not reaching PHP, how are you checking this? Not a trick question, just trying to "follow the route" a bit better. What variable is being returned if nothing is being sent?
__________________
Caimin Jones
Freelance web, flash + games developer
Caimin is offline   Reply With Quote
Old 06-07-2003, 08:13 AM   #5
simontheak
Simon
 
simontheak's Avatar
 
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
Default

Thanks for your time Caimin,

Now that I'm back home, I've attached the.fla and the php file that I'm using. The php file is just a simple if statement that takes a users name and outputs one of two options depending on what that name is.

As for knowing that the variable is empty, well I changed the script slightly to output the variable it was given. But nothing came out - the line was empty. Plus the script I downloaded from friendsofed.com behaved as though the variables were empty too - it kept reminding me that I needed to fill in both fields when I'd already done so.
Attached Files
File Type: zip phpprob.zip (2.7 KB, 421 views)
__________________
"That could be anybody's ass" - Mayor Quimby
simontheak is offline   Reply With Quote
Old 06-07-2003, 08:23 AM   #6
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

Change your PHP script to this and try it again...
PHP Code:
<?
    $name 
$_POST['name'];
    
$target "Simon";
    if (
$name == $target)
    {
        print 
"&result=" urlencode("That is a cool name  " $name);
    }
    else
    {
        print 
"&result=" urlencode("I don't think I know you  " $name);
    }
?>
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 06-07-2003, 09:50 AM   #7
simontheak
Simon
 
simontheak's Avatar
 
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
Default

Quote:
Originally posted by CyanBlue
PHP Code:
    $name $_POST['name']; 
Hey CyanBlue - that seems to have done it. Thanks alot.

Is that something that you have to do for every variable you want to transfer or is this something special? It's just it doesn't mention anything like that in the book ... and even the downloadable examples don't have that code in it - or are you just a genius way beyond your time?
__________________
"That could be anybody's ass" - Mayor Quimby
simontheak is offline   Reply With Quote
Old 06-07-2003, 03:06 PM   #8
Caimin
Senior Member
 
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
Default

Any time you send variables to PHP using POST the variables are stored in an array called $_POST.

If you sent a variable to PHP called "mayorQuimby" you'd be able to access it by using:

PHP Code:
$_POST['mayorQuimby'
The same idea applies when sending variables using GET, except the array is called $_GET, so

PHP Code:
$_GET['mayorQuimby'
would be used instead.

Hope this helps.
__________________
Caimin Jones
Freelance web, flash + games developer
Caimin is offline   Reply With Quote
Old 06-09-2003, 08:04 AM   #9
simontheak
Simon
 
simontheak's Avatar
 
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
Default

And to access those variables do I need to access the POST array every time rather than just using the variables directly?
__________________
"That could be anybody's ass" - Mayor Quimby
simontheak is offline   Reply With Quote
Old 06-09-2003, 08:10 AM   #10
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

I think this is what you are asking...

This sample...
PHP Code:
<?
    $target 
"Simon";
    if (
$_POST['name'] == $target)
    {
        print 
"&result=" urlencode("That is a cool name  " $_POST['name']);
    }
    else
    {
        print 
"&result=" urlencode("I don't think I know you  " $_POST['name']);
    }
?>
and this sample...
PHP Code:
<?
    $name 
$_POST['name'];
    
$target "Simon";
    if (
$name == $target)
    {
        print 
"&result=" urlencode("That is a cool name  " $name);
    }
    else
    {
        print 
"&result=" urlencode("I don't think I know you  " $name);
    }
?>
works the same way... So, it goes to your coding style, I guess???

(Correct me if I am wrong... )
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:16 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.