chaitra
chaitra

Reputation: 83

redirect is not working in both php & javascript

I had write some script, i tried Header & window.location both for redirection, but in this page redirect is not working...in other pages javascript window.location is working perfectly...

$insertquery = mysql_query("INSERT INTO members(UserName, Password, FirstName, LastName, Address, ContactNo, Url, Birthdate, Gender, profImage,curcity, age, married_status, college_name, batch, qualification, specilization, public_message)VALUES('$login','$password','$fname','$lname','$address','$cnumber','$email','$bday','$gender','$propic','$address','$age','$married_status','$coll','$batch','$qua','$specilization','$public_message')") or die(mysql_error());

 /*$page = "signup-success.php";                          
echo '<script>window.location = "'.$page.'";</script>';                                  
echo "login success";*/    

if($insertquery){
  $from = "[email protected]    "; // sender
  $subject = "Thank You For Registering Doctorskynet.com";
  $message = "Welcome to Doctorskynet.com"."<br/>";
  $message .= "Username:".$login."<br/>";
  $message .= "Password:".$password."<br/>";    
  $message = "Please click below link to activate your account<br/>";            

  // send mail
  //$mail = mail($email,$subject,$message,"From: $from\n");
  session_start();

  //Create query
  $qry="SELECT * FROM members WHERE UserName='clean($login)' AND Password='$password'";
  $result=mysql_query($qry);

  //Check whether the query was successful or not
  if($result) {
    if(mysql_num_rows($result) > 0) {
      //Login Successful
      session_regenerate_id();
      $member = mysql_fetch_assoc($result);
      $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
      $_SESSION['SESS_FIRST_NAME'] = $member['FirstName'];
      $_SESSION['SESS_USERNAME'] = $member['FirstName'].'-'.$member['LastName'];
      $_SESSION['SESS_LAST_NAME'] = $member['profImage'];

      $online = 1;                          
      //Update query      
      mysql_query("UPDATE members SET online = $online WHERE member_id='".$_SESSION['SESS_MEMBER_ID'] ."'");

      session_write_close();
      $page = "Home.php";                          
      echo '<script>window.location = "'.$page.'";</script>';  

      /*header("location: Home.php");
      exit();*/
    }
  }    
}

Upvotes: 0

Views: 72

Answers (2)

sakthi.krr
sakthi.krr

Reputation: 81

The below solution is will help for you

<script type="text/javascript">

window.location.replace("siteurl");

The above code will tell the script type to browser .I think you are missing the script type.

Upvotes: 0

Jon
Jon

Reputation: 13002

When using header() you're supposed to specify a full URL and I think Location needs a capital L:

header("Location: http://mydomain.com/Home.php");
exit;

Upvotes: 1

Related Questions