06-06-2003, 08:40 AM
|
#1
|
|
Simon
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
|
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
|
|
|
06-06-2003, 12:18 PM
|
#2
|
|
Senior Member
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
|
No, you don't need to set permissions for PHP files to run.
What code are you using to send your variables to PHP?
|
|
|
06-06-2003, 01:42 PM
|
#3
|
|
Simon
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
|
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
|
|
|
06-06-2003, 05:07 PM
|
#4
|
|
Senior Member
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
|
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?
|
|
|
06-07-2003, 08:13 AM
|
#5
|
|
Simon
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
|
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.
__________________
"That could be anybody's ass" - Mayor Quimby
|
|
|
06-07-2003, 08:23 AM
|
#6
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
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);
}
?>
|
|
|
06-07-2003, 09:50 AM
|
#7
|
|
Simon
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
|
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
|
|
|
06-07-2003, 03:06 PM
|
#8
|
|
Senior Member
Join Date: Jun 2001
Location: Rome, Italy.
Posts: 186
|
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.
|
|
|
06-09-2003, 08:04 AM
|
#9
|
|
Simon
Join Date: Mar 2002
Location: _UK.London.Bucks
Posts: 339
|
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
|
|
|
06-09-2003, 08:10 AM
|
#10
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
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...  )
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 07:31 PM.
///
|
|