title: After redirect, how to display error messages coming from original file?
body: <p>Here's what I'm trying to achieve: I want to redirect the user if any errors I check for are found to a html/php form (that the user see's first where inputs are previously created) with custom error messages.</p>
  
  <p>Details: The User see's the HTML/PHP form first where they enter names in a csv format. After they click create, the names are processed in another file of just php where the names are checked for errors and other such things. If an error is found I want the User to be redirected to the HTML/PHP form where they can fix the errors and whatever corresponding error messages are displayed. Once they fix the names the User can click the 'create user' button and processed again (without errors hopefully) and upon completion, redirect user to a page where names and such things are displayed. The redirect happens after the headers are sent. From what I've read this isn't the best thing but, for now, it'll do for me.</p>
  
  <p>Code For HTML/PHP form:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;HTML&gt;
      &lt;head&gt;
          &lt;title&gt;PHP FORM&lt;/title&gt;
      &lt;/head&gt; 
      &lt;body&gt;
  &lt;form method="post" action="processForm.php"&gt;
  
      Name: &lt;input type="text" name="names" required = "required"&gt;&lt;br&gt;
      &lt;input type="submit" value="Create Users" onclick="formInputNames"&gt;&lt;br&gt;
  
      Activate: &lt;input type="checkbox" name="activate"&gt;
  &lt;/form&gt;
  &lt;?php
  // include 'processForm.php';
  // errorCheck($fullname,$nameSplit,$formInputNames);
  ?&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>I tried messing around with 'include' but it doesn't seem to do anything, however, I kept it here to help illustrate what I'm trying to achieve.</p>
  
  <p>Code For Process: </p>
  
  <pre><code>$formInputNames = $_POST['names'];
  
  $active = (isset($_POST['activate'])) ? $_POST['activate'] : false;
  //checks if activate checkbox is being used
  $email = '@grabby.com';
  echo "&lt;br&gt;";
  echo "&lt;br&gt;";
  
  $fullnames = explode(", ", $_POST['names']);
  
  if ($active == true) {
      $active = '1';
      //sets activate checkbox to '1' if it has been selected
  }
  /*----------------------Function to Insert User---------------------------*/
           A Function is here to place names and other fields in database.
  /*-------------------------End Function to Insert User--------------------*/
  
  /*-----------------------Function for Errors---------------------*/
  
  function errorCheck($fullname,$nameSplit,$formInputNames){
      if ($formInputNames == empty($fullname)){
          echo 'Error: Name Missing Here: '.$fullname.'&lt;br&gt;&lt;br&gt;';
          redirect('form.php');
      }
      elseif ($formInputNames == empty($nameSplit[0])) {
          echo 'Error: First Name Missing in: '.$fullname.'&lt;br&gt;&lt;br&gt;';
          redirect('form.php');
      }
      elseif ($formInputNames == empty($nameSplit[1])) {
          echo 'Error: Last Name Missing in: '.$fullname.'&lt;br&gt;&lt;br&gt;';
          redirect('form.php');
      }
      elseif (preg_match('/[^A-Za-z, ]/', $fullname)) {
          echo 'Error: Found Illegal Character in: '.$fullname.'&lt;br&gt;&lt;br&gt;';
          redirect('form.php');
      }
  }
  
  /*-----------------------------End Function for Errors------------------------*/
  
  /*--------------------------Function for Redirect-------------------------*/
  
  function redirect($url){
      $string = '&lt;script type="text/javascript"&gt;';
      $string .= 'window.location = "' .$url. '"';
      $string .= '&lt;/script&gt;';
  
      echo $string;
  }
  
  /*-------------------------End Function for Redirect-----------------------*/
  
  //  Connect to database
       I connect to the database here
  
  foreach ($fullnames as $fullname) {
      $nameSplit = explode(" ", $fullname);
  
              //opens the database
  I Open the database here
  
          errorCheck($fullname,$nameSplit,$formInputNames);
  
          $firstName = $nameSplit[0];//sets first part of name to first name
          $lastName = $nameSplit[1];//sets second part of name to last name
          $emailUser = $nameSplit[0].$email;//sets first part and adds email extension
  
          newUser($firstName,$lastName,$emailUser,$active,$conn);
  
          redirect('viewAll.php');
          //echo '&lt;META HTTP-EQUIV="Refresh" Content="0; URL=viewAll.php"&gt;';
  //if you try this code out, you can see my redirect to viewAll doesn't work when errors are found...I would appreciate help fixing this as well. My immediate fix is using the line under it but I don't like it.
  }
  </code></pre>
  
  <p>Any help is certainly appreciated.Thank You</p>
  
  <p>Also it's worth noting I'm new to php. I would like to have an answer in php as well (if possible).</p>