
<?php
include('database/connection.php');
// echo "<pre>";
// print_r($_POST);
// die;
session_start();
if(isset($_REQUEST['submit']))
{
    /*$email = $_REQUEST['email'];
    $password = $_REQUEST['password'];
    $sql = "SELECT * FROM users WHERE id = 1" ;
    $result = mysqli_query($link, $sql);
      $row = mysqli_fetch_assoc($result);
      $emailDb = ($row['email']);
      $passwordDb = ($row['password']);
      if($email == $emailDb && $password == $passwordDb){
        header("Location: index.php");
        $_SESSION["email"] = $email;
      }else{
        header("Location: login.php");
      }*/
    
      
    // Retrieve user input
    $email = $_POST['email'];
    $password = $_POST['password'];
    
    // Query to check if user exists
    $query = "SELECT * FROM users WHERE email='$email' AND password='$password' AND status=1";
    $result = $link->query($query);
    
    if ($result->num_rows == 1) {
        // User is authenticated, store user info in session
        $user = $result->fetch_assoc();
        $_SESSION['user_id'] = $user['id'];
        $_SESSION['user_name'] = $user['name'];
        $_SESSION['email'] = $user['email'];
        $_SESSION['user_role'] = $user['role'];
        
        header("Location: dashboard.php"); // Redirect to dashboard or any other page
    } else {
        header("Location: login.php");
    }

      
      
      
}
?>