title: Include of validation.php file does not execute
body: <p>I have a form (add_company_form.php) in my submit_form_company.php that takes the values from POST and sends them to mysql trough a pdo connection. But I cant get my validation.php to validate the input. I want the user to stay on the same page which is why I dont have a action in the form. The code itself is not complete and there is alot of improvements that can be done, but Im stuck on the validation for now.. Am I on the right track by adding the validation.php before like my db.php?</p>
  
  <p>Submit_form_company.php</p>
  
  <pre><code>&lt;?php 
  if ($_SERVER['REQUEST_METHOD'] == "POST") {
      try {
          include('db.php');
          include('validation.php');
  
          if(empty($_SESSION["error_message"]) &amp;&amp; $_POST['submit_company']) {
  
              $STH = $conn-&gt;prepare("
                      INSERT INTO companies (Name,Notes,OrganizationNumber)
                      VALUES (:Name,:Notes,:OrganizationNumber)");
              $STH-&gt;bindParam(':Name', $_POST['Name'], PDO::PARAM_STR);
              $STH-&gt;bindParam(':Notes', $_POST['Notes'], PDO::PARAM_STR);
              $STH-&gt;bindParam(':OrganizationNumber', $_POST['OrganizationNumber'], PDO::PARAM_INT);
              $STH-&gt;execute();
          } elseif ($_SESSION["error_message"] &amp;&amp; $_POST['submit_edit']) {
              foreach ($_POST['company'] as $i =&gt; $value) {
                  $STH = $conn-&gt;prepare("
                          UPDATE companies
                          SET Name = :Name,Notes = :Notes,OrganizationNumber = :OrganizationNumber
                          WHERE Id = :Id");
                  $STH-&gt;bindParam(':Id', $value['Id'], PDO::PARAM_INT);
                  $STH-&gt;bindParam(':Name', $value['Name'], PDO::PARAM_STR);
                  $STH-&gt;bindParam(':Notes', $value['Notes'], PDO::PARAM_STR);
                  $STH-&gt;bindParam(':OrganizationNumber', $value['OrganizationNumber'], PDO::PARAM_INT);
                  $STH-&gt;execute();
              }
  
          }
          if(empty($_SESSION["error_message"])){
              echo "&lt;meta http-equiv='refresh' content='0'&gt;";
          }
  
  
      }
  
      catch (PDOException $e) {
          echo $e-&gt;getMessage();
      }
  
  }
  
  require("add_company_form.php"); 
  $DBH = null;
  ?&gt;
  </code></pre>
  
  <p>add_company_form.php</p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;form class="col-md-4 navbar-form" method="POST" action="" enctype="multipart/form-data"&gt;
      &lt;div class="form-group"&gt;
          &lt;label class="sr-only" for="Name"&gt;Name:&lt;/label&gt; &lt;input type="text" class="form-control" name="Name" placeholder="Name"&gt;&lt;br /&gt;
          &lt;label class="sr-only" for="Notes"&gt;Notes:&lt;/label&gt; &lt;input type="text" class="form-control" name="Notes" placeholder="Notes"&gt;&lt;br /&gt;
          &lt;label class="sr-only" for="OrganizationNumber"&gt;OrganizationNumber:&lt;/label&gt; &lt;input type="text" class="form-control" name="OrganizationNumber" placeholder="OrganizationNumber"&gt;&lt;br /&gt;
          &lt;input type="submit" name="submit_company" class="btn btn-default" value="Submit"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
      &lt;?php
  if(!empty($_SESSION["error_message"])){
      echo'&lt;div id="error_message" class="col-md-8"&gt;';
      print_alert_error($_SESSION["error_message"]);
      $_SESSION["error_message"] = ""; 
      echo'&lt;/div&gt;';   
  } ?&gt;-
  </code></pre>
  
  <p></p>
  
  <p>Validation.php</p>
  
  <pre><code>&lt;?
  $error = "";
  
  if(isset($_POST['submit_company'])) {
      $name = $_POST['Name'];
      $notes = $_POST['Notes'];
      $organization_number = $_POST['OrganizationNumber'];
  
      if (!ctype_alpha(str_replace(array("'", "-"), "",$name))) { 
          $error .= '&lt;p class="error"&gt;Name should be alpha characters only.&lt;/p&gt;';
      }
  
  }
  
  //Add error message to session
  if (!empty($error)){
      $_SESSION["error_message"] = $error;
  }
  ?&gt;
  </code></pre>
  
  <p>DB.php</p>
  
  <pre><code>&lt;?php 
  $servername = "127.0.0.1";
  $username = "root";
  $password = "";
  $dbname = "test";
  $conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES 'utf8'"));
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $conn-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  </code></pre>
  
  <p>?></p>