title: after validating data from a registration form, redirect to another page to log in
body: <p>i am new to php and mysql. I am trying to create a user registration form, validate the data, and then redirect to a login page, where they can enter their username and password to sign in. i have written the codes, but for some reason i'm not able to use the header() properly.
  Here is my code so far:
      
  
  <pre><code>$userErr= $passErr= $passErrc= $firstErr= $lastErr= $middle= $addErr= $cityErr=      $stateErr=$zipErr= $emailErr= $phoneErr= $passMatchErr="";
  
  $userID= $password= $pass_conf= $firstName= $lastName= $middle= $address= $city= $state= $zip= $email= $phone="";
  
  
  // Validate the form
  // use trim() function to remove unnecessary characters such as extra space, tab, newline,
  // use stripslashes(() to remove backslashes 
  // use htmlspecialchars() for security
  function test_input($data)
  {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
  
  
  if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
      // validating the form to see all required fields are entered
      if (empty($_POST["userID"]))
      {
          $userErr = "User ID is required";
      }
      else
      {
          $userID = test_input($_POST["userID"]);
      }
  
      if (empty($_POST["password"]))
      {
          $passErr = "Password is required";
      }
      else
      {
          $password = test_input($_POST["password"]);
      }
      if (empty($_POST["pass_conf"]))
      {
          $passErrc = "Confirm your password";
      }
      else
      {
          $pass_conf = test_input($_POST["pass_conf"]);
      }
  
      if (empty($_POST["firstName"]))
      {
          $firstErr = "First Name is required";
      }
      else
      {
          $firstName = test_input($_POST["firstName"]);
      }
  
      if (empty($_POST["lastName"]))
      {
          $lastErr = "Last Name is required";
      }
      else
      {
          $lastName = test_input($_POST["lastName"]);
      }
      if (empty($_POST["middle"]))
      {
          $middle = "";
      }
      else
      {
          $middle= test_input($_POST["middle"]);
      }
      if (empty($_POST["address"]))
      {
          $addErr = "Address is required";
      }
      else
      {
          $address = test_input($_POST["address"]);
      }
      if (empty($_POST["city"]))
      {
          $cityErr = "City is required";
      }
      else
      {
          $city = test_input($_POST["city"]);
      }
      if (empty($_POST["state"]))
      {
          $stateErr = "State is required";
      }
      else
      {
          $state = test_input($_POST["state"]);
      }
      if (empty($_POST["zip"]))
      {
          $zipErr = "Zip is required";
      }
      else
      {
          $zip = test_input($_POST["zip"]);
      }
      if (empty($_POST["email"]))
      {
          $emailErr = "Email is required";
      }
      else
      {
          $email = test_input($_POST["email"]);
      }
      if (empty($_POST["phone"]))
      {
          $phoneErr = "";
      }
      else
      {
          $phone = test_input($_POST["phone"]);
      }
  }   
  else
  {
      if($password != $pass_conf){
          $passMathErr= "Passwords do not match. Please, go back and re-enter the passwords!";
          // die($passMathErr);
      } else{
          // perform sql query to insert the data
          $sql="insert into users values('$userID', '$password', '$firstName', '$lastName', '$middle', '$address', '$city', '$state', '$zip', '$email', '$phone')";
          $result=mysql_query($sql, $connection);
          header("Location:login.html");
      }
  }
  ?&gt;  
  
  &lt;html lang="em"&gt;
  &lt;head&gt;
      &lt;title&gt; Registration &lt;/title&gt;
      &lt;style type="text/css"&gt;
          h1{
              text-align: left;
              font-weight:bold;
              font-size: 2em;
              color:#FFFF99;
              word-spacing: 0.3em;
              letter-spacing:0.1em;
              text-decoration:underline;
          }
          body{
              background-color: #421818;
          }
          .txtinput{
              margin-left:150px;
          }
          table{
              font-color:#99FF00;
          }
          .error {
              color: #FF0000;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt; Registration Form &lt;/h1&gt;&lt;br&gt;
      &lt;form name="reg" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" method="post"&gt;
          &lt;table style="color:#99FF00" border=0 cellspacing=0 cellpadding=2&gt;
              &lt;tr&gt;
                  &lt;td&gt;User ID * &lt;td&gt;&lt;input type="text" name="userID"/&gt;
                  &lt;span class="error"&gt;&lt;?php echo $userErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password *&lt;td&gt;&lt;input type="password" name="password" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $passErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Confirm Password *&lt;td&gt;&lt;input type="password" name="pass_conf" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $passErrc;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;First Name *&lt;td&gt;&lt;input type="text" name="firstName" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $firstErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Last Name *&lt;td&gt;&lt;input type="text" name="lastName" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $lastErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Middle&lt;td&gt;&lt;input type="text" name="middle" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $middle;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Address *&lt;td&gt;&lt;input type="text" name="address" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $addErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;City *&lt;td&gt;&lt;input type="text" name="city" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $cityErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;State *&lt;td&gt;&lt;input type="text" name="state" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $cityErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Zip *&lt;td&gt;&lt;input type="text" name="zip" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $zipErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Email *&lt;td&gt;&lt;input type="text" name="email"/&gt; 
                  &lt;span class="error"&gt;&lt;?php echo $emailErr;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Phone&lt;td&gt;&lt;input type="text" name="phone" /&gt;
                  &lt;span class="error"&gt;&lt;?php echo $phone;?&gt;&lt;/span&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;div class="txtinput"&gt;
              &lt;input type="submit" name="submit" value="Register"/&gt;   
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>