Ranjit
Ranjit

Reputation: 125

on successful registration redirect to a different page in php

I am trying to create a web site where the intention is that when the registration is successful redirect to finish.php else be on the same page i.e. register.php the code is as below:

try {
          $mail->send();
          $msg = "An email has been sent for verfication.";
          echo "<script type='text/javascript'>alert('$msg');</script>";
          redirect("finish.php");          
          $msgType = "success";

        }

in the above code the function of inserting in db is completed. alert message is shown on the page but the page is not redirected to finish.php my form submit looks like:

<form action="free_register.php"  class="form-horizontal well" method="post" name="f" onsubmit="return validateForm();">

Upvotes: 1

Views: 191

Answers (1)

Lund
Lund

Reputation: 272

You should use header("Location: dashboard.php")

UPDATE:

You have two options. Either redirect with js or php.

/* PHP */

try {
    $mail->send();
    $msg = "An email has been sent for verfication.";
    header("Location: finish.php");         
    $msgType = "success";
}

/* JS */
try {
    $mail->send();
    $msg = "An email has been sent for verfication.";
    echo "<script type='text/javascript'>alert('$msg');</script>";  
    echo "<script type='text/javascript'>window.location = 'finish.php';</script>";       
    $msgType = "success";
}

Both examples work. If not, check your try block or clarify "what does not work".

Upvotes: 1

Related Questions