mrlarge Posted March 23, 2006 Share Posted March 23, 2006 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 9NB. 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 7Well, 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 9Back 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. Quote Link to comment https://forums.phpfreaks.com/topic/5577-newbie-undefined-variable-error/ Share on other sites More sharing options...
wildteen88 Posted March 23, 2006 Share Posted March 23, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5577-newbie-undefined-variable-error/#findComment-19908 Share on other sites More sharing options...
mrlarge Posted March 23, 2006 Author Share Posted March 23, 2006 [!--quoteo(post=357555:date=Mar 23 2006, 12:05 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 23 2006, 12:05 PM) [snapback]357555[/snapback][/div][div class=\'quotemain\'][!--quotec--]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. Quote Link to comment https://forums.phpfreaks.com/topic/5577-newbie-undefined-variable-error/#findComment-19956 Share on other sites More sharing options...
craygo Posted March 23, 2006 Share Posted March 23, 2006 with the globals off you can do this(Who_are_you.php)[code]<html><head><title>Who Are You?</title></head><body><form action="you_are.php" method="GET">Please enter your name:<br />I am...<?if(isset($_GET['person'])){$person = $_GET['person'];} else {$person = "";}print('<input type="text" name="person" value="' . $person .'"size="15" />');?><input type="submit" value="Go!" size="15" /></form></body></html>[/code](You_are.php)[code]<html><head><title>You Are ...</title></head><body><?php$person = $_GET['person'];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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5577-newbie-undefined-variable-error/#findComment-19962 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.