How can I redirect to "Thank You" page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haitashi
    New Member
    • Jun 2007
    • 96

    How can I redirect to "Thank You" page?

    Users register on my page. It's a multi-page form.

    After my insert statement, I have the following code:

    [PHP]if(!$insert){
    die("There's little problem: ".mysql_error() );
    }

    echo "Thank you for registering. Please check your inbox for your registration confirmation email.";[/PHP]

    Instead of echoing that, I want to redirect the user to a thank you page.
    Any ideas? Help is greatly appreciated.
  • juro
    New Member
    • Jul 2007
    • 3

    #2
    Originally posted by Haitashi
    Users register on my page. It's a multi-page form.

    After my insert statement, I have the following code:

    [PHP]if(!$insert){
    die("There's little problem: ".mysql_error() );
    }

    echo "Thank you for registering. Please check your inbox for your registration confirmation email.";[/PHP]

    Instead of echoing that, I want to redirect the user to a thank you page.
    Any ideas? Help is greatly appreciated.
    This is one option:
    [code=php]if(!$insert){
    die("There's little problem: ".mysql_error() );
    }

    require "thankyou.h tm";[/code]

    Comment

    • Haitashi
      New Member
      • Jun 2007
      • 96

      #3
      Thanks but that didn't work for me. Can't I direct the user to a URL?

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        Use header() for this purpose.
        [PHP]if(!$insert){
        die("There's little problem: ".mysql_error() );
        }

        header("Locatio n: thankyou.html") ;
        exit;[/PHP]
        Make sure there should not be any output before header().

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by mwasif
          Use header() for this purpose.
          [PHP]if(!$insert){
          die("There's little problem: ".mysql_error() );
          }

          header("Locatio n: thankyou.html") ;
          exit;[/PHP]
          Make sure there should not be any output before header().
          This is of course be the best way, and should be used if at all possible. (Tho the exit() call is kind of redundant.)

          But if you absolutely can not hold of outputting before the redirect, you can always use this javascript trick:
          [code=php]
          echo '<script type="text/javascript">loc ation.href="tha nkyou.html";</script>';
          [/code]

          Comment

          • gregerly
            Recognized Expert New Member
            • Sep 2006
            • 192

            #6
            or use an output buffer

            Comment

            • Haitashi
              New Member
              • Jun 2007
              • 96

              #7
              Awesome!

              Thanks guys. I used this:

              Code:
              if(!$insert){
              die("There's little problem: ".mysql_error());
              }
              
              
              echo '<script type="text/javascript">location.href="http://www.google.com";</script>';
              Of course I'm not gonna use Google, but I just wanted to make sure it worked ^_^.

              Comment

              Working...