I am having difficulty with header redirecting me to index.html from my login page. I'm not sure header is even the way to go but it is all that I could find on page redirection.
This code is just a simple login page which checks the useame and password against a MySQL database.
The problem I am having is inside the loop:
if(mysqli_num_rows($res) == 1){
header("Location: index.php");
exit();
}
full code for login.php:
<?php
//Coects to MySQL database using sql_coect.php
require "sql_coect.php";
?>
<?php
if(isset($_POST['useame'])) {
$useame = $_POST['useame'];
$password = $_POST['password'];
$sql = "SELECT * FROM login_test WHERE useame='".$useame."' AND password='".$password."' LIMIT 1";
$res = mysqli_query($coection, $sql);
if(mysqli_num_rows($res) == 1){
header("Location: index.php");
exit();
} else {
echo "Invalid login information!";
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>login</title>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<form name="login" method="post" action="login.php">
<h3>Login</h3>
<p>Useame: </p><input type="text"name="useame">
<p>Password: </p><input type="password" name="password">
<br/>
<input type="submit"name="submit"value="log in">
</form>
<script src="../script.js" type="text/javascript"></script>
</body>
</html>
While I'm sure the rest of my code is far from perfect I am just really looking at how to redirect to a new page if the user is authenticated in the database? Is there a better option than header in my case or am I just implementing it wrong?
