<?php

require_once ('database.php');

$search_criteria = $_POST['search_criteria'];

//cadena consulta
$query = "SELECT id, first_name, last_name, email, birthday FROM authors
         WHERE first_name LIKE '%". $search_criteria . "%' OR last_name LIKE '%". $search_criteria . "%'";
$authors = [];
$errors = ['data'=> false];

$getAuthors = $db-> query($query);

if($getAuthors->num_rows > 0 ) {
    while($data = $getAuthors->fetch_assoc()){
        $authors[] = $data;
    }
    echo json_encode($authors);
    //echo $query;
} else {
    echo json_encode($errors);
    //echo $query;
}



