What are the best practices for passing HTML content from JavaScript to PHP for database insertion?

When passing HTML content from JavaScript to PHP for database insertion, it is important to properly sanitize and escape the data to prevent SQL injection attacks. One common method is to use the `htmlspecialchars()` function in PHP to encode the HTML content before inserting it into the database.

// Retrieve the HTML content from JavaScript
$html_content = $_POST['html_content'];

// Sanitize the HTML content
$sanitized_content = htmlspecialchars($html_content);

// Insert the sanitized content into the database
// $db_connection is assumed to be the database connection object
$query = "INSERT INTO table_name (html_content) VALUES ('$sanitized_content')";
$result = mysqli_query($db_connection, $query);

if ($result) {
    echo "HTML content inserted successfully";
} else {
    echo "Error inserting HTML content";
}