
<!DOCTYPE html>
<?php include('../config/constants.php'); ?>
<html lang="en" dir="ltr">
<head>
  <link rel='stylesheet' href='logincss.css'>
</head>
<body>
  <?php
  if (isset($_SESSION['login'])) {
    echo $_SESSION['login'];//displaying session msg
    unset($_SESSION['login']);//REMOVING SESSION MSG
    // code...
  }
  if (isset($_SESSION['not-login-msg'])) {
    echo $_SESSION['not-login-msg'];//displaying session msg
    unset($_SESSION['not-login-msg']);//REMOVING SESSION MSG
    // code...
  }
   ?>


   <div class="container">
     <label>login to our system</label>
     <br><br>
     <button onclick="document.getElementById('id01').style.display='block'" class='btnsuccess'type="button" name="button">Login</button>
   </div>
   <div  id="id01" class="modal">
     <form class="content" action="#" method="post">
       <div class="imgcontainer">
         <span onclick="document.getElementById('id01').style.display='none'"class="close">&times;</span>
         <img src="user.svg" alt=""  >
       </div>
       <div class="container">
         <label>Email</label>
         <br>
         <input class="inputresponsive"type="text" name="email"  placeholder="enter your email" required>
         <br>
         <label>password</label>
         <br>
         <input class="inputresponsive"type="password" name="password" placeholder="enter your password" required>
         <br>
         <input class="login"type="submit" name="submit" value="Login">
         <br><br>
         <input class="" type="checkbox" name="check" value="">Remember me
       </div>
       <div class="container">
         <button onclick="document.getElementById('id01').style.display='none'" class="btndanger" type="button" name="button">Cansel</button>

       </div>
     </form>
   </div>

</body>

</html>
<?php
//check whether the submit btn is clicked or not
 if (isset($_POST['submit'])) {
   //process for login
   //1.get the data frm login form
   //$username = $_POST['username'];

   $raw_password = md5($_POST['password']);

   $email = mysqli_real_escape_string($conn, $_POST['email']);
   $password = mysqli_real_escape_string($conn, $raw_password);
   //2.sql to check whether the user with the username and password exists or not
   $sql = "SELECT * FROM tbl_admin WHERE email='$email' AND password='$password'";
   //3.execute the querry
   $res = mysqli_query($conn, $sql);
   //4.count rows to check whether the user exists or not
   $count = mysqli_num_rows($res);
   if ($count>0) {
     // user available and login success
     $_SESSION['login'] = "<div class='success'>Login Successful.</div>";
     $_SESSION['user'] = $username;//to check whether the user is logged in or not and logout will unset it
     //redirect to the dashboard
     header('location:'.SITEURL.'backend/');
   }else{
     //user not available and login failed
     $_SESSION['login'] = "<div class='error'>Login Failed.</div>";
     //redirect to the dashboard
     header('location:'.SITEURL.'backend/login.php');
   }
 }else{

   //error occurred during data proccessing
 }
 ?>
