redirect on form submit

Viewed 104

I am new to php. I have tried the following code to redirect the page when sign In button is clicked, but it is not happening. please help me editing the code. probably, there is an error in header() function. Have I used the header() function correctly?

<body>
<?php
  $emailErr = $passwordErr = "";
  $email = $password = "";

  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (empty($_POST["email"])) {
          $emailErr = "*Email is required";
      } else {
          $email = test_input($_POST["email"]);
          // check if e-mail address syntax is valid
           if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
               $emailErr = "Invalid email format"; 
           }
      }

      if (empty($_POST["password"])) {
          $passwordErr = "*Password is required";
      } else {
         $password = test_input($_POST["password"]);
      }
   }

function test_input($data)
{
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

include("signInform.php");
if($_POST["sign"])
{
  header('Location:signInform.php');
}
?>

<br/><br/><br/><br/><br/>

<h1>WELCOME</h1>
<h2>Please, Register Yourself!</h2>
<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 

<label>E-mail:</label><br />
<input type="text" name="email"/>
<span class="error"> <?php echo $emailErr;?></span>
<br />

<label>Password:</label><br />
<input type="password" name="password"/>
<span class="error"> <?php echo $passwordErr;?></span>
<br /><br />
<input type="submit" value="Register"/><br/>

<p>If already a user, Sign in! </p>
<input type="submit" value="Sign In" name="sign"/><br/>
</form>
</body>
4 Answers
Related