What best practices should be followed when handling HTML content in PHP for database storage?

When handling HTML content in PHP for database storage, it is important to properly sanitize the input to prevent SQL injection attacks and cross-site scripting vulnerabilities. One common approach is to use the `htmlspecialchars()` function to encode special characters in the HTML content before storing it in the database. This ensures that the HTML content is stored safely and can be displayed without causing any security risks.

// Sanitize HTML content before storing in the database
$html_content = htmlspecialchars($_POST['html_content']);

// Insert sanitized HTML content into the database
$query = "INSERT INTO table_name (html_content) VALUES ('$html_content')";
mysqli_query($connection, $query);