
- You are not logged in. | Login
November 17, 2006 5:54 am
- monkeydude
- Member


help with processing a form
hi,
I'm trying to use this form code to get the users firstname, lastname and parse to the php variables:
<html> <body> <FORM ACTION="welcome.php" METHOD=GET> Firstname: <input type=text name="firstname"><br> Lastname: <input type=text name="lastname"> <input type=SUBMIT value="GO"> </form> </html> </body>
and this is the welcome.php code:
<html>
<body>
<?php
echo ("Welcome to our Web site, $firstname $lastname!");
?>
</body>
</html>When i put the firstaname and lastname in the form, the output is only:
Welcome to our Web site!
this is the /var/log/httpd/error_log message:
[Mon Apr 17 09:44:44 2006] [error] [client 127.0.0.1] PHP Notice: Undefined variable: firstname in /var/www/html/welcome.php on line 4, referer: http://127.0.0.1/mysql/form.php
Please help!
November 23, 2006 1:08 pm
- senjor_itc
- Member


Re: help with processing a form
Hi!
This happens, b/c the register_globals is turned off. This is right behavior of server setup.
Instead of this, you should use the following:
<html>
<body>
<?php
if (!isset($_GET['firstname'])){
$_GET['firstname'] = '';
}
if (!isset($_GET['lastname'])){
$_GET['lastname'] = '';
}
echo "Welcome to our Web site, $_GET['firstname'] $_GET['lastname']!";
?>
</body>
</html>


