<?php
session_start();
include('includes/config.php');

if (!isset($_GET['id'])) {
  echo json_encode(["error" => "No ID provided"]);
  exit;
}

$id = intval($_GET['id']);
$sql = "SELECT id, AuthorID AS author_id, AuthorName AS author_name FROM tblauthors WHERE id = :id LIMIT 1";
$query = $dbh->prepare($sql);
$query->bindParam(':id', $id, PDO::PARAM_INT);
$query->execute();

$result = $query->fetch(PDO::FETCH_ASSOC);

if ($result) {
  echo json_encode($result);
} else {
  echo json_encode(["error" => "Author not found"]);
}
?>
