Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Passing Problem

Status
Not open for further replies.

sipps

Technical User
Feb 9, 2003
133
GB
Hi,

I just got a book on PHP and trying to learn the form stuff. I have these two pages, one that takes a users name and address and sends it to the other page:

listing9.2.php:
<form action=&quot;listing9.3.php&quot; method=&quot;GET&quot;>
<input type=&quot;text&quot; name=&quot;user&quot;>
<br>
<textarea name=&quot;address&quot; rows=&quot;5&quot; cols=&quot;40&quot;>
</textarea>
<br>
<input type=&quot;submit&quot; value=&quot;hit it!&quot;>
</form>

listing9.3.php:
<html>
<head>
<title>Listing 9.3 Reading input from the form in Listing 9.2</title>
</head>
<body>
<?php
print &quot;Welcome <b>$user</b><P>\n\n&quot;;
print &quot;Your address is:<P>\n\n<b>$address</b>&quot;;
?>
</body>
</html>

The browser shows this error message regardless of whether global variables are on or off:

Notice: Undefined variable: user in C:\Program Files\Apache Group\Apache2\htdocs\Testcode\listing9.3.php on line 7
Welcome

Notice: Undefined variable: address in C:\Program Files\Apache Group\Apache2\htdocs\Testcode\listing9.3.php on line 8
Your address is:

I am well frustrated as it says this should be easy! I have tried using &quot;GET&quot; and &quot;POST&quot;. Please can anyone shed some light?

Thanks!
 
Sorry guys, have just tried something that I found on a site, and it works! Stupid books!

I used:

<?php
print &quot;Welcome <b>$_POST[user]</b><P>\n\n&quot;;
print &quot;Your address is:<P>\n\n<b>$_POST[address]</b>&quot;;
?>

and that worked fine!

So could you tell me if I should leave global variables off or on?

Sorry to waste anyone's time!
 
Being that his form uses get, i suggest that you use post, but if you want get use:

$_GET['var'] --BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top