<?php
include ('mysqli_con.php');

$username = $_POST["username"];
$password = $_POST["password"];
$flag = 'true';

$result = mysqli_query($conn, 'SELECT adminLog_id,username, password from adminlog');

if($result == FALSE){
  die(mysqli_error());
}
if($result){
  while($row = mysqli_fetch_array($result)){
    if($row['username'] == $username && $row['password'] == $password)
    {
      header('location: adminuser.php');
    }
    else {
      if($flag  == 'true'){
        redirect();
        $flag = 'false';
      }
    }
  }
}
function redirect(){
  echo "<script>
  alert('Invalid username or password');
  window.location.href='admin.php';
  </script>";
}
?>
