<?php 
session_start();
require 'includes/db_connect.php';  // Your DB connection
?>
<?php
    if(isset($_POST['login'])){
        $loguser = strtolower(htmlentities(trim(mysqli_real_escape_string($conn, $_POST['email']))));
        $password = md5($_POST['password']);
        $reg_date = Date("d-M-Y");
        $time = time();
        $time2 = Date("H:i:s", $time);
        $time3 = "{$reg_date} {$time2}";
        $online = "online";
        
        $query = "SELECT * FROM admin WHERE email = '{$loguser}' AND password ='{$password}'";
        $run_query = mysqli_query($conn, $query);
        
        if(mysqli_num_rows($run_query)== 1 ) {
            
                    
                    $_SESSION['user_id']= $user_id;
                    header("location: dashboard.php");
                    
                    
                    
                }
            }
        else{
            $error = "<i class='fa fa-info-circle'></i> Login Failed.Email/Incorrect password.";
            
            
        }
    
?>

<?php include 'includes/header.php'; ?>

<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-4">
            <?php if (isset($error)): ?>
                <div class="alert alert-danger text-center"><?php echo $error; ?></div>
            <?php endif; ?>
            <div class="card shadow">
                <div class="card-header text-center text-white" style="background-color: orange;">
                    <h5>Admin Login</h5>
                </div>
                <div class="card-body">
                    <form method="POST" action="">
                        <div class="mb-3">
                            <label>Email</label>
                            <input type="email" name="email" class="form-control" required />
                        </div>
                        <div class="mb-3">
                            <label>Password</label>
                            <input type="password" name="password" class="form-control" required />
                        </div>
                        <button type="submit" name="login" class="btn btn-orange w-100" style="background-color: orange; color: white;">Login</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'includes/footer.php'; ?>


