<?php
session_start();
include('connection.php');

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

$sql_check = "SELECT * FROM rr_410_profile WHERE email = '$email'";
$result = $conn->query($sql_check);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $stored_hashed_password = $row['password'];
    
    if (password_verify($password, $stored_hashed_password)) {
        $_SESSION['profile_id'] = $row['profile_id'];
        $_SESSION['email'] = $email;
        header("Location: save_profile_id.php");
        exit();
    } else {
        echo "<script> alert('Invalid password. Please try again.'); location.href='../html/login.html'; </script>";
    }
} else {
    echo "<script>alert('Incorect or not registered e-mail.'); location.href='../html/login.html';</script>";
}

$conn->close();
?>
