I am using TMForm.js to execute bat/MailHandler.php file to validate username and password for a login form. I am using Firefox Firebug to check the request and response for bat/MailHandler.php and that is works fine, it checks the database verifies the username and password but fails to transfer back the control to after login page using location header as shown in the code below. Header location is not working in my bat/MailHandler.php file. I am pasting the code here, please do guide me with the solution.
<?php
     include("../connect.php");
     $userName=$_POST['name'];
     $password=$_POST['state'];
     //$value=$_POST['check'];
     $sql="SELECT * from login where email='".$userName."'";
     $result=mysql_query($sql) or die(mysql_error());
     while ($row=mysql_fetch_array($result)){
         $memID=$row['id'];
         $userNamedb=$row['email'];
         $passworddb=$row['password'];
     }
    if($userName==$userNamedb && $password==$passworddb){
        session_start();
        $_SESSION['id']= $memID;
        $_SESSION['uname']= $userName;
        $_SESSION['upassword']= $password;
        header("location:../afterlogin.php");
    }
    else{
        $flag=1;
        header("location:../memberlogin.php?valid=".$flag);
    }
?>
 
     
    