<?php
    session_start();
    require("../includes/database_connect.php");

    $username = $_POST['username'];
    $password = $_POST['password'];
   

    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";

    $result = mysqli_query($conn, $sql);
    if (!$result) {
        $response = "Something went wrong!";
        $_SESSION['error'] = $response;
    }

    $row_count = mysqli_num_rows($result);

    if ($row_count == 0) {
        $response = "Login failed! Invalid email or password.";
        $_SESSION['error'] = $response;
        header('location: ../login.php');
    }else {
        $row = mysqli_fetch_assoc($result);
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['username'] = $row['username'];
        $_SESSION['roles'] = 'admin';
    
        $response =  "Login successful!";
        $_SESSION['success'] = $response;
        header('location: ../index.php');
    }
       
 

?>