website/public/API/getPost.php
2021-04-13 10:33:40 +02:00

24 lines
No EOL
515 B
PHP

<?php
include "./lib/config.php";
include "./lib/mysql.php";
$id = $conn->real_escape_string($_GET["id"]);
$result = $conn->query("SELECT * FROM posts WHERE id=$id");
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
} else {
die("Post not found");
}
$title = $row["title"];
$content = $row["content"];
$date = $row["date"];
$id = $row["id"];
header('Content-Type: application/json');
echo json_encode([
"title" => $title,
"content" => $content,
"date" => $date,
"id" => $id
]);