title: How do I redirect to the registration page with an error message upon submit error
body: <p>I am trying to create a registration form that checks to see if the Email and passwords entered by the user match, if all forms are complete, and if the email has been previously used to register. When there is in fact an error, I would like the code to display the error message at the top of the registration form. </p>
  
  <p>However, I cannon't figure out how to make the error message display above the registration inputs. Instead, what happens is that the error message replaces the registration inputs and appears alone (requiring the user to refresh the page to try registering again). This is my first post on stackoverflow, so please excuse me if my coding jargon is off! Below is the code I have been trying to use.</p>
  
  <pre><code>&lt;?php
  
  // Connect to database server
  mysql_connect("localhost", "root") or die (mysql_error ());
  
  // Select database
  mysql_select_db("mydatabase") or die(mysql_error());
  
      //Checks to make sure form has been submitted
      if (isset($_POST['submit'])) { 
  
  //Checks to make sure all fields are complete
  if (!$_POST['FirstName'] | !$_POST['LastName'] | !$_POST['Username']| !$_POST['Username2']| !$_POST['Password']| !$_POST['Password2'] ) {
      die('You did not complete all of the required fields');
  }
  
  //Check to see if email has already been used to reigster
  if (!get_magic_quotes_gpc()) {
      $_POST['Username'] = addslashes($_POST['Username']);
  }
  
  $usercheck = $_POST['Username'];
  
  $check = mysql_query("SELECT Username FROM people WHERE Username = '$usercheck'") 
  or die(mysql_error());
  
  $check2 = mysql_num_rows($check);
  
  //Email has already been used to register message
  if ($check2 != 0) {
      die('Sorry, the Email '.$_POST['Username'].' has already been used to register.');
  }
  
  //Confirm that Emails match
  if ($_POST['Username'] != $_POST['Username2']) {
      die('The Email addresses you entered do not match. ');
  }
  
  //Confirm that passwords match
  if ($_POST['Password'] != $_POST['Password2']) {
      die('The passwords you entered do not match. ');
  }
  
  //Encrypt the password and add slashes if needed
  $_POST['Password'] = md5($_POST['Password']);
  if (!get_magic_quotes_gpc()) {
      $_POST['Password'] = addslashes($_POST['Password']);
      $_POST['Username'] = addslashes($_POST['Username']);
      }
  
      // now we insert it into the database
  $insert = "INSERT INTO people(FirstName,LastName,Username,Password) VALUES ('" . $_POST["FirstName"] . "','" . $_POST["LastName"] . "','" . $_POST["Username"] . "','" . $_POST["Password"] . "')";
  
  $add_member = mysql_query($insert);
  ?&gt;
  </code></pre>
  
  <p><h1>Registered</h1></p>
  
  <p><p>Thank you, you have registered - you may now login.</p></p>
  
  <pre><code>    &lt;?php 
      } 
      else 
      {   
      ?&gt;
      &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
          &lt;table border="0"&gt;
              &lt;tr&gt;&lt;td&gt;First Name:&lt;/td&gt;&lt;td&gt;
                  &lt;input type="text" name="FirstName" maxlength="60"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Last Name:&lt;/td&gt;&lt;td&gt;
                  &lt;input type="text" name="LastName" maxlength="60"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Email Address:&lt;/td&gt;&lt;td&gt;
                  &lt;input type="text" name="Username" maxlength="60"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Confirm Email Address:&lt;/td&gt;&lt;td&gt;
                  &lt;input type="text" name="Username2" maxlength="60"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Password (8 character minimum):&lt;/td&gt;&lt;td&gt;
                  &lt;input type="password" name="Password"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Confirm Password:&lt;/td&gt;&lt;td&gt;
                  &lt;input type="password" name="Password2"&gt;
              &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;th colspan=2&gt;
          &lt;input type="submit" name="submit" value="Register"&gt;&lt;/th&gt;&lt;/tr&gt; &lt;/table&gt;
      &lt;/form&gt;
      &lt;?php
      }
      ?&gt;
  </code></pre>