title: php code showing up on webpage
body: <p>I am new to php. Currently I am following the tutorial on this website:<a href="http://www.tutorialspoint.com/php/php_validation_example.htm" rel="nofollow noreferrer">tutoialspoint</a>. The code is also on that website.</p>
  
  <p>The problem I am facing is with the action tag on line 66. I am getting extra characters on my form page because of it. Also, when I submit the form it goes to "Not Found" page.
  <a href="https://i.stack.imgur.com/E8BCx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E8BCx.png" alt="form page"></a>
  <a href="https://i.stack.imgur.com/PPJqP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PPJqP.png" alt="submission page"></a></p>
  
  <p>I can fix this by leaving action tag blank. However, I would like to know why this error is happening with the default code. </p>
  
  <pre><code>    &lt;html&gt;   
     &lt;head&gt;
        &lt;style&gt;
           .error {color: #FF0000;}
        &lt;/style&gt;
     &lt;/head&gt;
  
     &lt;body&gt;
        &lt;?php
           // define variables and set to empty values
           $nameErr = $emailErr = $genderErr = $websiteErr = "";
           $name = $email = $gender = $comment = $website = "";
  
           if ($_SERVER["REQUEST_METHOD"] == "POST") {
              if (empty($_POST["name"])) {
                 $nameErr = "Name is required";
              }else {
                 $name = test_input($_POST["name"]);
              }
  
              if (empty($_POST["email"])) {
                 $emailErr = "Email is required";
              }else {
                 $email = test_input($_POST["email"]);
  
                 // check if e-mail address is well-formed
                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    $emailErr = "Invalid email format"; 
                 }
              }
  
              if (empty($_POST["website"])) {
                 $website = "";
              }
              else {
                 $website = test_input($_POST["website"]);
              }
  
              if (empty($_POST["comment"])) {
                 $comment = "";
              }else {
                 $comment = test_input($_POST["comment"]);
              }
  
              if (empty($_POST["gender"])) {
                 $genderErr = "Gender is required";
              }else {
                 $gender = test_input($_POST["gender"]);
              }
           }
  
           function test_input($data) {
              $data = trim($data);
              $data = stripslashes($data);
              $data = htmlspecialchars($data);
              return $data;
           }
        ?&gt;
  
        &lt;h2&gt;Absolute classes registration&lt;/h2&gt;
  
        &lt;p&gt;&lt;span class = "error"&gt;* required field.&lt;/span&gt;&lt;/p&gt;
  
        &lt;form method = "post" action = "&gt;?php 
           echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt;
           &lt;table&gt;
              &lt;tr&gt;
                 &lt;td&gt;Name:&lt;/td&gt;
                 &lt;td&gt;&lt;input type = "text" name = "name"&gt;
                    &lt;span class = "error"&gt;* &lt;?php echo $nameErr;?&gt;&lt;/span&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                 &lt;td&gt;E-mail: &lt;/td&gt;
                 &lt;td&gt;&lt;input type = "text" name = "email"&gt;
                    &lt;span class = "error"&gt;* &lt;?php echo $emailErr;?&gt;&lt;/span&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                 &lt;td&gt;Time:&lt;/td&gt;
                 &lt;td&gt; &lt;input type = "text" name = "website"&gt;
                    &lt;span class = "error"&gt;&lt;?php echo $websiteErr;?&gt;&lt;/span&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                 &lt;td&gt;Classes:&lt;/td&gt;
                 &lt;td&gt; &lt;textarea name = "comment" rows = "5" cols = "40"&gt;&lt;/textarea&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                 &lt;td&gt;Gender:&lt;/td&gt;
                 &lt;td&gt;
                    &lt;input type = "radio" name = "gender" value = "female"&gt;Female
                    &lt;input type = "radio" name = "gender" value = "male"&gt;Male
                    &lt;span class = "error"&gt;* &lt;?php echo $genderErr;?&gt;&lt;/span&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;td&gt;
                 &lt;input type = "submit" name = "submit" value = "Submit"&gt; 
              &lt;/td&gt;
  
           &lt;/table&gt;
  
        &lt;/form&gt;
  
        &lt;?php
           echo "&lt;h2&gt;Your given values are as:&lt;/h2&gt;";
           echo $name;
           echo "&lt;br&gt;";
  
           echo $email;
           echo "&lt;br&gt;";
  
           echo $website;
           echo "&lt;br&gt;";
  
           echo $comment;
           echo "&lt;br&gt;";
  
           echo $gender;
        ?&gt;
  
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>