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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.