null, 'title' => '', 'content' => '', 'excerpt' => '', 'image_url' => '' ]; $pageTitle = 'Create New Post'; $action = 'editor.php'; // Edit mode if (isset($_GET['id'])) { try { $pdo = db(); $stmt = $pdo->prepare("SELECT * FROM posts WHERE id = ?"); $stmt->execute([$_GET['id']]); $post = $stmt->fetch(); if (!$post) { // Post not found, redirect or show error header("Location: admin.php?error=notfound"); exit; } $pageTitle = 'Edit Post'; $action = 'editor.php?id=' . $_GET['id']; } catch (PDOException $e) { error_log("DB Error: " . $e->getMessage()); die("Error fetching post. Check logs."); } } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = $_POST['title'] ?? ''; $content = $_POST['content'] ?? ''; $excerpt = $_POST['excerpt'] ?? ''; $imageUrl = $_POST['image_url'] ?? ''; $id = $_POST['id'] ?? null; // Basic validation if (empty($title) || empty($content)) { $error = "Title and Content are required."; } else { try { $pdo = db(); if ($id) { // Update $stmt = $pdo->prepare("UPDATE posts SET title = ?, content = ?, excerpt = ?, image_url = ? WHERE id = ?"); $stmt->execute([$title, $content, $excerpt, $imageUrl, $id]); } else { // Insert $stmt = $pdo->prepare("INSERT INTO posts (title, content, excerpt, image_url) VALUES (?, ?, ?, ?)"); $stmt->execute([$title, $content, $excerpt, $imageUrl]); } header("Location: admin.php?saved=true"); exit; } catch (PDOException $e) { error_log("DB Error: " . $e->getMessage()); $error = "Error saving post. Check logs for details."; } } } ?> <?php echo $pageTitle; ?>

A short summary of the post, shown on the main blog page.
URL for the post's main image. A new random placeholder is generated for you.
Cancel