I have a simple admin panel on my site, where you can get access by entering your username and password. But for some reason it does not work. What could be the problem?
validate.php:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$sql = $connection->prepare("SELECT login, password FROM adminpanel WHERE login=? AND password=?");
$login = $_POST['login'];
$password = $_POST['password'];
$sql->bind_param('ss', $login, $password);
$sql->execute();
if($sql->num_rows == 1){
$_SESSION['user'] = $login;
header('location: ../admin.php');
}else{
$_SESSION['logwarning'] = 'Wrong login or password!';
header('location: ../login.php');
};
$connection->close();
};
login.php:
<form action="configs/validate.php" method="POST">
<img class="mb-4" src="img/main/logo.png" alt="Logo" width="90">
<input type="text" name="login" value="<?= $_POST['login'] ?? ''; ?>" id="inputLogin" class="form-control mb-1" placeholder="Login" required="" autofocus="" autocomplete="on">
<input type="password" name="password" id="inputPassword" class="form-control mt-1" placeholder="Password" required="" autocomplete="on">
<input type="hidden" name="token" value="<?= $_SESSION['token']; ?>">
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
</form>
Also, in case of an indefinite attempt to enter data, I want the entered name value (login field) not to disappear. I added this value there from the $_POST variable, but for some reason it is not saved.