<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title> ADMIN - Login</title>

    <!-- Bootstrap core CSS-->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin.css" rel="stylesheet">

  </head>

  <body class="bg-dark">

    <div class="container">
      <div class="card card-login mx-auto mt-5">
        <div class="card-header">Login</div>
        <div class="card-body">
<?php
include("includes/db.php");
if(isset($_POST['login'])){
$stmt=$mysqli->prepare("select * from login where username=? AND password=?");
$stmt->bind_param("ss", $user_name, $newpass);
$user_name=mysqli_real_escape_string($mysqli, $_POST['username']);
$user_pass=mysqli_real_escape_string($mysqli, $_POST['password']); 
$newpass=md5($user_pass);
  //  $stmt->bind_param($username, $newpass);
    $stmt->execute();
    $stmt->store_result();


 if($stmt->num_rows > 0) 
{
        $_SESSION['username']=$user_name;
echo '<script type="text/javascript">';
echo 'setTimeout(function () {';
echo 'swal("Success!","data successfully added","success").then( function(val) {';
echo 'if (val == true) window.location.href = \'index.php\';';
echo '});';
echo '}, 200);  </script>';
    }
    else{
    echo"username or password is in correct";
    }
}

?>

            
          <form action="login.php" method="post">
            <div class="form-group">
              <div class="form-label-group">
                <input type="text" id="inputEmail" name="username" class="form-control" placeholder="User Name" required="required" autofocus="autofocus">
                <label for="inputEmail">User Name</label>
              </div>
            </div>
            <div class="form-group">
              <div class="form-label-group">
                <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required="required">
                <label for="inputPassword">Password</label>
              </div>
            </div>
            <button type="submit" name="login" class="btn btn-primary btn-block">Login</button>
          </form>
          
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>

  </body>

</html>
