Passing Variables Between Forms.

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
agatt42
Forum Newbie
Posts: 3
Joined: Tue Nov 26, 2002 6:49 pm

Passing Variables Between Forms.

Post by agatt42 »

Hi folks,

I'm very new to PHP and have been having trouble configuring my installation on Windows XP Professional. I have installed Apache HTTP Server 1.3.27 and am using PHP 4.2.3 using the Apache Module DLL (Sapi Module). I run Apache in a console window also (not as a service) and the status line at the top of the console window says "Apache/1.3.27 (Win32) PHP/4.2.3 running...

So it all appears fine to me and I have run some sample PHP scripts with no problems. However, as soon as I try to do something to do with variables like create a simple form and pass a variable from one to another it won't work.

My sample code is below;

test1.php
------------------------------------------------------------------------
<?php
# test1.php
echo "<FORM METHOD=\"POST\" ACTION=\"test2.php\">";
echo "<INPUT TYPE=\"TEXT\" NAME=\"var1\" VALUE=\"$var1\">";
echo "<INPUT TYPE=\"SUBMIT\" VALUE=\"TEST\">";
echo "</FORM>";
?>

test2.php
------------------------------------------------------------------------
<?php
# test2.php
echo "The value of \$var1 is \"$var1\"";
?>

My output is always;
The value of $var1 is ""

I have experimented with POST and GET and neither helps, so I have come to the conclusion that somewhere in my configuration of PHP with Apache I have gone wrong... I am getting a little bit frustrated and would appreciate any help that can be offered. Thanks in advance!

Cheers,
Adrian.

email: letsdosomethingthatreallycooks@hotmail.com.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Try:

Code: Select all

&lt;?php
echo "The value of \$var1 is "$_POST&#1111;'var1']""; 
?&gt;
I'd suggest you read the sticky posts at the top of this forum.

Specifically, viewtopic.php?t=511
.
agatt42
Forum Newbie
Posts: 3
Joined: Tue Nov 26, 2002 6:49 pm

Post by agatt42 »

Thanks Bill,

Just gave that a go and got this result...

"Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\apache\htdocs\test2.php on line 4"

Is there any particular reason why my first test code shouldn't work? This was copied from a test I used with an older version of PHP and it worked fine.

Thanks!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

common mistake. read http://www.php.net/manual/en/language.t ... ng.parsing to learn more about it and try

Code: Select all

&lt;?php
echo "The value of \$var1 is "$_POST&#1111;var1]""; 
?&gt;
or

Code: Select all

&lt;?php
echo "The value of \$var1 is "{$_POST&#1111;'var1']}""; 
?&gt;
or

Code: Select all

&lt;?php
echo 'The value of $var1 is "', $_POST&#1111;'var1'], '"';
?&gt;
I prefer the last one but that's matter of opinion.
agatt42
Forum Newbie
Posts: 3
Joined: Tue Nov 26, 2002 6:49 pm

Is this style of using string variables new?

Post by agatt42 »

Thanks a lot Volka! That works fine. I am still a little lost with how variables are being passed from form to form though.

Why does the following code echo FALSE? It used to echo TRUE with PHP 4.1.1?

test2.php
-----------------------------------------------------
<?php
# test2.php
if ($var1)
echo 'TRUE';
else
echo 'FALSE';
?>

Thanks for your help!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

that's the topic of the thread Bill H mentioned
viewtopic.php?t=511
Post Reply