Its real simple.
The $POST[] super global array is empty until your form posts data to it so what I did was check if the "user" key had a value.
if(isset($_POST['user']))
And if it was set it process the posted data if it was not set it displyed the form.
Now of course you needed it to display an error if the data submitted was wrong. And of course if it is wrong they will want to try and resubmit. So if the data was not correct it would set the "$status variable to "Incorrect" and display it with the form again.
Hmm, actually there is slight error in how I made that.
<?php
$status = '';
if(isset($_POST['user'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
if (($user=="Admin") && ($pass=="pass")) {
echo "Correct!";
}
else {
$status = "Incorrect!";
}
}
if((!isset($_POST['user'])) || ($status != '')) {
?>
<html>
<body>
<?php echo $status; ?><br />
<form action="index.php" method=POST>
Username: <input type=text name=user><br />
Password: <input type=password name=pass><br />
<input type=submit value="Login!">
</form>
</body>
</html>
<?php
}
?>
There that is better.
Notice I just changed the else to an if that checks whether if $_POST['user'] is not set or if $status is not ''. So if either is true it will show the form.