<?php
session_start();

$host = 'localhost';
$user = 'ahmeuesz_dino';
$pwd = 'X39IW2ho3^5h6d_5';
$dbname = 'ahmeuesz_myapp';

$conn = mysqli_connect($host, $user, $pwd, $dbname);

if (isset($_POST['login'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];

    $query = "SELECT * FROM users WHERE email='$email' AND password='$password'";
    $result = mysqli_query($conn, $query);

    if (mysqli_num_rows($result) > 0) {
        $user = mysqli_fetch_assoc($result);
        $_SESSION['user'] = $user;

        header("Location: home.php");
        exit();
    } else {
        $message = "❌ Invalid email or password. Please try again.";
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <link rel="stylesheet" href="style/form.css">
    <style>
        .message {
            text-align: center;
            color: red;
            font-weight: bold;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Login</h2>
        <?php if (!empty($message)) { echo "<div class='message'>$message</div>"; } ?>
        <form method="POST" action="">
            <input type="email" name="email" placeholder="Email Address" required>
            <input type="password" name="password" placeholder="Password" required>
            <input type="submit" name="login" value="Login">
        </form>
        <p>Don't have an account? <a href="registration.php">Register</a></p>
    </div>
</body>
</html>
