redirecting the page using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gubbachchi
    New Member
    • Jan 2008
    • 59

    redirecting the page using php

    Hi all,

    In my application there is a link in page 1 by name "plan", when it is clicked it directs to page2 which contains a form with many fields and submit button. When the user clicks the submit button, php and mysql code is written in page3 to store data in mysql. Here is code I am using

    page2

    Code:
    <form name="plan" action="page3.php" method="POST">
    Name : <input type="text" name="Uname">
    Age: <input type="text" name="Uage">
    <input type="submit" value="GO"> 
    </form>
    My problem is when the form is submitted in the page 2, I need to go to page 1 instead of page 3, but I can't write the php code in page 1 instead of page 3 because of some security reasons.
    How can I solve this problem, how to redirect from page 3 to page 1 after execution of page 3 code. Can anybody help me

    With regards

    page3

    Code:
    <?php
    $Uname = $_POST['Uname'];
    $Uage = $_POST['Uage'];
    
    $sql = "INSERT INTO user_info(user_name,user_age) VALUES('$Uname','$Uage')";
    $result = mysql_query($sql);
    ?>
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Use a header() redirect.

    [php]
    # query mysql
    header("Locatio n: http://yoursite.com/page1.php");
    [/php]

    Regards :)

    Comment

    • gubbachchi
      New Member
      • Jan 2008
      • 59

      #3
      Originally posted by markusn00b
      Use a header() redirect.

      [php]
      # query mysql
      header("Locatio n: http://yoursite.com/page1.php");
      [/php]

      Regards :)
      Thanks for the reply

      I have used header() redirect but I am getting the warning
      Warning: Cannot modify header information - headers already sent by (output started at /var/www/kilorie/kil_ver3/page3.php:3) in /var/www/kilorie/kil_ver3/page3.php on line 146

      can you give me some hint

      Comment

      • rpnew
        New Member
        • Aug 2007
        • 189

        #4
        Originally posted by gubbachchi
        Thanks for the reply

        I have used header() redirect but I am getting the warning
        Warning: Cannot modify header information - headers already sent by (output started at /var/www/kilorie/kil_ver3/page3.php:3) in /var/www/kilorie/kil_ver3/page3.php on line 146

        can you give me some hint
        Hi,
        Post your page 3 code here...

        Regards,
        RP

        Comment

        • gubbachchi
          New Member
          • Jan 2008
          • 59

          #5
          Originally posted by rpnew
          Hi,
          Post your page 3 code here...

          Regards,
          RP

          Hi,

          here is my page3 code
          Code:
          <html>
          <body>
                <?php
             
                $Uname = $_POST['Uname'];
             
                $Uage = $_POST['Uage'];
             
                 
             
                $sql = "INSERT INTO user_info(user_name,user_age) VALUES('$Uname','$Uage')";
             
                $result = mysql_query($sql);
             
                ?>
          </body>
          </html>

          Comment

          • Amzul
            New Member
            • Oct 2007
            • 130

            #6
            there is a target attribute to form alement one of them is _parent

            i never use it before but sounds like it can help you,

            on page 2
            <form target="_parent " action="page3.p hp" method="post">

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by Amzul
              there is a target attribute to form alement one of them is _parent

              i never use it before but sounds like it can help you,

              on page 2
              <form target="_parent " action="page3.p hp" method="post">
              No.

              You are using a header after html has been output - big NONO!

              Have a read about the header function on php.net

              Regards.

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                This is a cheap way of doing it, but if you want to redirect half way through your script you can output a meta refresh line in html:

                [HTML]<meta http-equiv="refresh" content="2;url= http://mywebsite.com">[/HTML]

                **The 2 means it will wait 2 seconds, you can change that to 0 if you want.

                This can go anywhere and will do what you want I think.

                Comment

                Working...