0

Hi, I am doing Home & Learn PHP Tutorial.I got to the lesson about forms.
I keep getting this error:
PHP Notice: Undefined index: username in C:\inetpub\wwwroot\basicForm.php on line 7.
This is the code:
<!DOCTYPE HTML PUBLIC -//W3C/DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>A Basic Html Form</title>
<?PHP
$username = $_POST['username'];
print($username);
?>
</head>
<body>
<FORM NAME="form1" METHOD="POST" ACTION = "basicForm.php">
<INPUT TYPE="text" VALUE="username" NAME="username">
<INPUT TYPE = "Submit" NAME = "submit1" VALUE = "Login">
</FORM>
</body>
</html>
It says to ignore the error message and click on submit or login button in this case.The problem
is that the browser IE9 just displays the error messaage, I cannot click the button because I cannot see it.
If I don't fix this I will not be able to go ahead with the tutorial.Any idea? Thank you

2
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by Fiorentino01^
0

Change this:

<?PHP
$username = $_POST['username'];
print($username);
?>

to:

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $username = $_POST['username'];
    print($username);
}
?>

and it should work, bye!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.