prepare("SELECT * FROM posts WHERE id = ?");
$stmt->execute([$post_id]);
$post = $stmt->fetch();
} catch (PDOException $e) {
$message = '
Error: ' . $e->getMessage() . '
';
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$content = $_POST['content'] ?? '';
$author = $_POST['author'] ?? '';
if ($title && $content && $author) {
try {
$pdo = db();
$stmt = $pdo->prepare("UPDATE posts SET title = ?, content = ?, author = ? WHERE id = ?");
$stmt->execute([$title, $content, $author, $post_id]);
header('Location: admin.php');
exit;
} catch (PDOException $e) {
$message = 'Error: ' . $e->getMessage() . '
';
}
} else {
$message = 'Please fill in all fields.
';
}
}
if (!$post) {
echo "Post not found.
";
require_once __DIR__ . '/includes/footer.php';
exit;
}
?>
Edit Post