What are the best practices for handling duplicate posts in PHP forums?

Duplicate posts in PHP forums can be handled by implementing a check to see if a post with the same content already exists before inserting a new post. This can help prevent clutter and confusion on the forum. One way to do this is by comparing the content of the new post with existing posts in the database using a unique identifier, such as the post title or content.

// Check if a post with the same content already exists
$existing_post = $db->query("SELECT * FROM posts WHERE content = '$new_post_content'")->fetch();

if($existing_post) {
    // Duplicate post found, display an error message
    echo "This post already exists.";
} else {
    // Insert the new post into the database
    $db->query("INSERT INTO posts (content) VALUES ('$new_post_content')");
    echo "Post successfully added.";
}