prepare("SELECT image FROM blogs WHERE blog_id = ?"); $check_stmt->bind_param("i", $article_id); $check_stmt->execute(); $result = $check_stmt->get_result(); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $image = $row['image']; } $check_stmt->close(); } // Check if this is an update or insert if ($article_id) { // Update existing blog $stmt = $conn->prepare("UPDATE blogs SET title = ?, content = ?, description = ?, category = ?" . ($image ? ", image = ?" : "") . " WHERE blog_id = ?"); if ($image) { $stmt->bind_param("sssssi", $title, $content, $description, $category, $image, $article_id); } else { $stmt->bind_param("ssssi", $title, $content, $description, $category, $article_id); } } else { // Insert new blog $stmt = $conn->prepare("INSERT INTO blogs (author, title, content, description, category, date, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("issssss", $user_id, $title, $content, $description, $category, $date, $image); } $stmt->execute(); $stmt->close(); header("Location: blog.php");