PDA

View Full Version : Why?


defeater
08-17-2002, 10:47 AM
help me with this notice.

When I select "go" button then get notice as follows:

!PHP Notice: Undefined variable: firstname in E:\Studying\PHP\handon\welcome.php on line 2 PHP Notice: Undefined variable: lastname in E:\Studying\PHP\handon\welcome.php on line 2


I have two .php file. That is ex4.php and welcome.php with code as follows:

ex4.php
<html>
<body>
<FORM ACTION="welcome.php" METHOD=GET>
First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
Last Name: <INPUT TYPE=TEXT NAME="lastname">
<INPUT TYPE=SUBMIT VALUE="GO">
</FORM>
</html>
</body>

welcome.php

<html>
<?php echo( "$firstname $lastname!" );?>
</html>

Alex Piotto
08-17-2002, 11:22 AM
Hi defeater, try this, call it test.php and test it...

<html>
<body>
<FORM ACTION="<? PHP_SELF ?>" METHOD=POST>
First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
Last Name: <INPUT TYPE=TEXT NAME="lastname">
<INPUT TYPE=SUBMIT VALUE="GO" NAME="hallobutton">
</FORM>
</html>
</body>

<?

if ($hallobutton) {

$firstname = ($firstname);
$lastname = ($lastname);

echo "Hallo $firstname $lastname!";

}

?>

Hope this helps
Alex

Ökii
08-17-2002, 11:34 AM
Other than the form method change to POST from GET, you may also find the snag within the php configuration. If register globals is set to OFF (as is default for all recent builds), you'd need either

$_POST['firstname'];
or
$HTTP_POST_VARS['firstname'];

defeater
08-17-2002, 04:19 PM
Thanks Alex Piotto and Okii.