<?php
session_start();
$conn = mysqli_connect('localhost', 'root', '', 'myapp');
$msg = '';

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

    if ($email && $password) {
        $q = "SELECT * FROM image_table WHERE email='$email' AND password='$password'";
        $res = mysqli_query($conn, $q);
        if ($res && mysqli_num_rows($res) == 1) {
            $row = mysqli_fetch_assoc($res);
            $_SESSION['user_id'] = $row['id'];
            $_SESSION['name'] = $row['name'];
            $_SESSION['email'] = $row['email'];
            $_SESSION['profile'] = $row['profile_image'];
            header('Location: home.php');
            exit;
        } else {
            $msg = 'Invalid credentials';
        }
    } else {
        $msg = 'Please fill all fields';
    }
}
?>
<!DOCTYPE html>
<html>
<head><title>Login</title></head>
<body>
<h2>Login</h2>
<form method="post">
Email: <input type="email" name="email"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
<p style="color:red;"><?php echo $msg; ?></p>
<a href="registration.php">Register</a>
</body>
</html>
