24 lines
625 B
PHP
24 lines
625 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
$q = $_GET['q'] ?? '';
|
|
|
|
if (strlen($q) < 2) {
|
|
echo json_encode([]);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT id, name, phone, email FROM customers WHERE name LIKE ? OR phone LIKE ? LIMIT 10");
|
|
$searchTerm = "%$q%";
|
|
$stmt->execute([$searchTerm, $searchTerm]);
|
|
$customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode($customers);
|
|
} catch (Exception $e) {
|
|
error_log("Customer Search Error: " . $e->getMessage());
|
|
echo json_encode(['error' => 'Database error']);
|
|
}
|