Reputation: 303
I got this code, in login.php:
<!DOCTYPE html>
<html>
<head>
<title>login.php</title>
<charset="utf8" />
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
echo "It works!";
}
?>
</head>
<body>
<h1>Log in:</h1>
<form method="POST" action="login.php" autocomplete="off">
Username: <input type="text" name="username" required="required" /> <br />
Password: <input type="password" name="password" required="required" /> <br/>
<input type="submit" value="Login" />
</form>
</body>
</html>
I am a php beginner, and I am trying to post data to the same page. After testing I discovered that the php did execute, but didn't echo "It works".
Any help for this is appreciated.
Upvotes: 3
Views: 4610
Reputation: 7937
You have printed the text in the head..
You should give the echo statement inside the body tag.Your code supposed to look like this..
<!DOCTYPE html>
<html>
<head>
<title>login.php</title>
<meta charset="utf8" />
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
echo "It works!";
}
?>
<h1>Log in:</h1>
<form method="POST" action="login.php" autocomplete="off">
Username: <input type="text" name="username" required="required" /> <br />
Password: <input type="password" name="password" required="required" /> <br/>
<input type="submit" value="Login" />
</form>
</body>
</html>
Upvotes: 11