35570-vm/book.php
Flatlogic Bot 9671081d9c 1
2025-11-08 12:20:22 +00:00

37 lines
979 B
PHP

<?php
require_once 'db/config.php';
// Get book ID from query string
$book_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$book_id) {
header("Location: index.php");
exit;
}
$pdo = db();
// Fetch book details
$stmt = $pdo->prepare("SELECT b.*, u.username FROM books b JOIN users u ON b.user_id = u.id WHERE b.id = ?");
$stmt->execute([$book_id]);
$book = $stmt->fetch();
if (!$book) {
// Redirect if book doesn't exist
header("Location: index.php");
exit;
}
?>
<?php require_once 'header.php'; ?>
<div class="card">
<div class="card-body">
<h1 class="card-title"><?php echo htmlspecialchars($book['title']); ?></h1>
<h6 class="card-subtitle mb-2 text-muted">by <a href="/author.php?id=<?php echo $book['user_id']; ?>"><?php echo htmlspecialchars($book['username']); ?></a></h6>
<p class="card-text"><?php echo nl2br(htmlspecialchars($book['description'])); ?></p>
</div>
</div>
<?php require_once 'footer.php'; ?>