<?php
// public/check_phone.php
require __DIR__ . '/../includes/db.php';
require __DIR__ . '/../includes/helpers.php';
$phone = preg_replace('/[^0-9]/','', $_GET['phone'] ?? '');
if (strlen($phone)!==10) json_response(['success'=>true,'exists'=>false]);
$stmt = $pdo->prepare('SELECT COUNT(*) FROM residents WHERE phone=:phone');
$stmt->execute(['phone'=>$phone]);
$cnt = (int)$stmt->fetchColumn();
json_response(['success'=>true,'exists'=>($cnt>0)]);
