title: PHP error Header Already Sent with no whitespace or previous echo, print
body: <p>I'm not sure why this code is throwing a headers already sent. I've looked at:
  <a href="https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php">How to fix &quot;Headers already sent&quot; error in PHP</a></p>
  
  <p>and am still getting the error. It's encoded in ANSI, I've typed it in notepad++, there seems to be no whitespace... any help would be appreciated it. The error is coming from line 8.</p>
  
  <p>Code follows:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Form Testing&lt;/title&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php 
    if($_POST['formSubmit'] == "Submit")  {
       $errorMessage = "";
       $varName = htmlspecialchars($_POST['formName'], ENT_QUOTES, 'UTF-8');
       $varMovie = htmlspecialchars($_POST['formMovie'], ENT_QUOTES, 'UTF-8');
       if(empty($varName)){
        $errorMessage .= "&lt;li&gt;You forgot to enter a name!&lt;/li&gt;";
       }
       if(empty($varMovie)){
       $errorMessage .= "&lt;li&gt; You forgot to enter a movie!&lt;/li&gt;";
       }
       if(!empty($errorMessage)){
          echo("&lt;p&gt; There was an error with your form: &lt;/p&gt; \n");
          echo("&lt;ul&gt;".$errorMessage. "&lt;/ul&gt; \n");
       }else{
          $fs = fopen("mydata.csv","a");
           fwrite($fs,$varName . ", " . $varMovie . "\n");
           fclose($fs);
           header("Location: ThankYou.html");
           echo "Hello ".$varName.". Your favorite movie is: ".$varMovie."!";
           exit;
      }
    }else{
      echo "Welcome! Please enter your name and movie preference";
    }
  ?&gt;
  &lt;form action="index.php" method="post"&gt;
      Which is your favorite movie?
       &lt;input type="text" name="formMovie" maxlength="50" value="&lt;?=$varMovie;?&gt;"&gt;
      What is your name?
      &lt;input type="text" name="formName" maxlength="50" value="&lt;?php echo $varName;?&gt;"&gt;
      &lt;input type="submit" name="formSubmit" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>