<?php
session_start();
include '../../secure/dbconn.php'; // This should include your database connection code

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = $_POST['email'];
    $password = $_POST['password'];

    // Query to check user credentials
    $stmt = $conn->prepare('SELECT * FROM users WHERE email_address = ? AND password = ?');
    $stmt->bind_param('ss', $email, $password);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();
        // Store user data in session
        $_SESSION['user'] = $user;
        // Redirect to accounts page
        header('Location: ../index.php');
    } else {
        // Redirect back to login page with error message
        header('Location: index.php?error=invalid_credentials');
    }
}
?>