<?php
// Database configuration
require 'shikanisha.kts.php';

// Get search term from GET request
$searchTerm = '%' . $_GET['foodSearch'] . '%';

// Prepare SQL statement
$sql = "SELECT * FROM food WHERE name LIKE ?";

// Prepare and bind parameters
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "s", $searchTerm);

// Execute query
mysqli_stmt_execute($stmt);

// Get result
$result = mysqli_stmt_get_result($stmt);

// Fetch data as associative array
$foods = mysqli_fetch_all($result, MYSQLI_ASSOC);

// Close statement and connection
mysqli_stmt_close($stmt);
mysqli_close($conn);

// Return JSON response
header('Content-Type: application/json');
echo json_encode($foods);
?>
