I don't understand the problem in my code.I am trying to redirect the user if username and password are correct.
I read from a documentation that "header must be called before any actual output is sent". What kind of output is this referring to? I don't think I'm outputting anything. Here is my code. Thanks in advance.
<?php
require "index-header.html";
?>
<div class="display">
<?php
if(isset($_POST["logout"])) {
session_unset();
session_destroy();
}
if(isset($_POST["login"])) {
$name = $_POST["name"];
$password = $_POST["password"];
// connect to database
$db = connect();
$query = "SELECT admin_name, admin_password FROM login WHERE admin_name = :name AND admin_password = :password";
$login = $db->prepare($query);
$login->execute(array(
":name" => $name,
":password" => $password
));
if($login->rowCount()) {
// start session
$_SESSION["admin"] = "Laura";
header("Location:admin.php");
exit;
}
else {
echo "<p class='message'>Incorrect username or password</p><br>";
require "login-form.html";
}
}
else {
require "login-form.html";
}
?>
</div>