mrlarge
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by mrlarge
-
-
Hi Guys.
Yep, am a newbie and the second bit of code I write wont work (the first was helloworld - would be difficult to not get that working!)
Anyway, the code I am using is:
(Who_are_you.php)
<html>
<head>
<title>Who Are You?</title>
</head>
<body>
<form action="you_are.php">
Please enter your name:<br />
I am...
<?php print('<input type="text" name="person" value="' . $person .
'"size="15" />');
?>
<input type="submit" value="Go!" size="15" />
</form>
</body>
</html>
(You_are.php)
<html>
<head>
<title>You Are ...</title>
</head>
<body>
<?php
print('Well, hello ' . $person . ', nice to meet you!');
print('<br />');
print('<a href="who_are_you.php?person=' . urlencode($person) . '">
Back to who are you?</a>');
?>
</body>
</html>
The output I get is:
(Who are you.php):
Please enter your name:
I am...
Notice: Undefined variable: person in c:\Inetpub\wwwroot\PHP-tests\Mastering PHP 4.1\Listing 1.3\who_are_you.php on line 9
NB. It does display the textbox and button, and when I submit I get:
Notice: Undefined variable: person in c:\Inetpub\wwwroot\PHP-tests\Mastering PHP 4.1\Listing 1.3\YOU_ARE.php on line 7
Well, hello , nice to meet you!
Notice: Undefined variable: person in c:\Inetpub\wwwroot\PHP-tests\Mastering PHP 4.1\Listing 1.3\YOU_ARE.php on line 9
Back to who are you?
the value $person is passed over in the url:
[a href=\"http://mysql_server/PHP-tests/Mastering%20PHP%204.1/Listing%201.3/you_are.php?person=nick\" target=\"_blank\"]http://mysql_server/PHP-tests/Mastering%20...php?person=nick[/a]
Oh, and I am using PHP 5.1.2 on IIS5 (Win XP Professional).
Nick.
Hope someone can help.
Regards,
Nick.
Newbie - Undefined variable error
in PHP Coding Help
Posted
If you parsing the variable [b]person[/b] over the url then you will want to use the $_GET superglobal array instead, ie $_GET['person'];
This is because you have register_globals turn off. So you will need to use the superglobal array instead.
[/quote]
Thanks for letting me know that the cause was register_globals was off. I turned it on and it worked. However, this does lead to security issues as stated in the narratives in php.ini, but the code I am going through is research anyway so for the time being that doesn't matter. I will also look at superglobal arrays at some point as well. I tried the $_GET['person'] in my code and it still didn't work until I turned register_globals on. Could you please post the alternative code to me (Ie. Your version with the $_GET change) so I can see what I have to do in future if I intend to leave register_globals turned off.
Thanks,
Nick.