What are common mistakes to avoid when combining HTML and PHP code?

One common mistake to avoid when combining HTML and PHP code is forgetting to properly escape PHP output within HTML to prevent cross-site scripting vulnerabilities. To solve this issue, always use functions like `htmlspecialchars()` to escape any dynamic content being output within HTML.

<?php
// Incorrect way without escaping output
$name = "<script>alert('XSS attack');</script>";
echo "<p>Welcome, $name!</p>";

// Correct way with output escaping
$name = "<script>alert('XSS attack');</script>";
echo "<p>Welcome, " . htmlspecialchars($name) . "!</p>";
?>