Using post of get

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nick2price
Forum Newbie
Posts: 18
Joined: Fri Nov 13, 2009 5:49 pm

Using post of get

Post by nick2price »

Hi. I am a bit confused. I am trying to send a variable from php to as3, but dont know how to assign it in php. My HTML is simple

Code: Select all

 <html> 
 <head><title>Test Page</title></head> 
 <body> 
 <h2>Data Collection</h2><p> 
<form action="getName.php" method="post">
 <p>Your name: 
  <input type="text" name="name" /></p>
 <p><input type="submit" /></p>
</form>

 </body> 
 </html>
It is the name variable I want sent. In my php, I am doing

Code: Select all

<param name="FlashVars" value="myVar=<?php "$name" ?>" />	
It is the value part I am having issues with. I dont know if I need to use post or get to assign it to myVar, or how I can even do this,

Any help appreciated.

cheers
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using post of get

Post by califdon »

Your form specifies the method as POST, so you must retrieve the value from the $_POST environment array in the second PHP script.

Then, when you use it embedded in HTML, you have to echo it.

Code: Select all

<?php 
...
$name = $_POST['name'];
...
?>
...
<param name="FlashVars" value="myVar='<?php echo $name;  ?>'" /> 
User avatar
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: Using post of get

Post by hypedupdawg »

When you are assigning the value in your form, you are putting it in direct quotes. this will make the value literally "$name" rather than the variable $name. To do this you need to say

Code: Select all

<param name="FlashVars" value="myVar=<?php print $name; ?>" /> 
//or
<param name="FlashVars" value="myVar=<?php echo $name; ?>" /> 
You then pick the variable up as califdon said, using the $_POST method.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using post of get

Post by califdon »

Note: you can use echo or print interchangeably.
Post Reply