What are some common syntax errors that can occur when mixing PHP and HTML code, and how can they be avoided?

One common syntax error when mixing PHP and HTML code is forgetting to close PHP tags before entering HTML code, which can result in unexpected output or errors. To avoid this, always remember to properly close PHP tags before switching to HTML code.

<?php
  // PHP code here

?>

<!DOCTYPE html>
<html>
  <head>
    <title>Example Page</title>
  </head>
  <body>
    <!-- HTML code here -->
  </body>
</html>