<?php
include 'db_conn.php';
header('Content-Type: application/json');

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

    $stmt = $conn->prepare("SELECT id FROM users WHERE email = ?");
    $stmt->bind_param("s", $email);
    $stmt->execute();
    $result = $stmt->get_result();
    // Pārbauda, vai e-pats neeksistē datubāzē
    if ($result->num_rows > 0) {
        // Ja aizņemts, atgriež JSON un paziņo ka e-pats ir aizņemts
        echo json_encode(['taken' => true]);
    } else {
        // E-pasts nav aizņemts
        echo json_encode(['taken' => false]);
    }
} else {
    echo json_encode(['taken' => false]);
}
$conn->close();
?>
