How can it be checked if an article already exists and how can it be updated?

To check if an article already exists, you can query the database using the article's title or unique identifier. If a result is returned, then the article already exists. To update the article, you can use an UPDATE query to modify the existing article's content.

// Check if article already exists
$query = "SELECT * FROM articles WHERE title = :title";
$stmt = $pdo->prepare($query);
$stmt->execute(['title' => $title]);
$existingArticle = $stmt->fetch();

if($existingArticle) {
    // Update existing article
    $updateQuery = "UPDATE articles SET content = :content WHERE id = :id";
    $updateStmt = $pdo->prepare($updateQuery);
    $updateStmt->execute(['content' => $newContent, 'id' => $existingArticle['id']]);
    echo "Article updated successfully";
} else {
    echo "Article does not exist";
}