What are the best practices for closing threads in PHP forums to ensure proper resolution of issues and prevent further discussion?

Issue: Closing threads in PHP forums is essential to ensure proper resolution of issues and prevent further discussion. This can help maintain organization and prevent unnecessary clutter in the forum. PHP Code Snippet:

// Check if user has permission to close threads
if($user->hasPermission('close_threads')) {
    // Update thread status to closed in the database
    $thread_id = $_POST['thread_id'];
    $query = "UPDATE threads SET status = 'closed' WHERE id = $thread_id";
    $result = mysqli_query($conn, $query);
    
    if($result) {
        echo "Thread closed successfully.";
    } else {
        echo "Error closing thread.";
    }
} else {
    echo "You do not have permission to close threads.";
}