How to transfer the variable to next page?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Murphy

    #1

    How to transfer the variable to next page?

    The first page have the pre-define variable. How to transfer to next
    php page?
    Thanks

  • Erwin Moller

    #2
    Re: How to transfer the variable to next page?

    Alex Murphy wrote:
    [color=blue]
    > The first page have the pre-define variable. How to transfer to next
    > php page?
    > Thanks[/color]

    Hi Alex,

    You can do so in different ways.
    If you make a link to the next page, you can pass it via the URL:


    You can also store the variable in a session.
    Look up SESSION at www.php.net to get started.
    ($_SESSION[] is per-user.)

    You can also store the variable somewhere on a database or in a file.

    What is the best way completely depends on what you are trying to achieve,
    but you didn't tell us a lot.

    Regards,
    Erwin Moller

    Comment

    • Alex Murphy

      #3
      Re: How to transfer the variable to next page?

      Its work...!!

      Thanks Erwin

      Comment

      • Paul Lautman

        #4
        Re: How to transfer the variable to next page?

        Erwin Moller wrote:[color=blue]
        > Alex Murphy wrote:
        >[color=green]
        >> The first page have the pre-define variable. How to transfer to next
        >> php page?
        >> Thanks[/color]
        >
        > Hi Alex,
        >
        > You can do so in different ways.
        > If you make a link to the next page, you can pass it via the URL:
        > http://www.mysite.com/nextpage.php?myvar=23
        >
        > You can also store the variable in a session.
        > Look up SESSION at www.php.net to get started.
        > ($_SESSION[] is per-user.)
        >
        > You can also store the variable somewhere on a database or in a file.
        >
        > What is the best way completely depends on what you are trying to
        > achieve, but you didn't tell us a lot.
        >
        > Regards,
        > Erwin Moller[/color]

        Or if doing a post, you can store it in a hidden input field.


        Comment

        • Alex Murphy

          #5
          Re: How to transfer the variable to next page?

          But... how to post a predefined variable?

          Comment

          • David Haynes

            #6
            Re: How to transfer the variable to next page?

            Alex Murphy wrote:[color=blue]
            > But... how to post a predefined variable?
            >[/color]

            The first step is to get php to send the predefined value to the web
            browser. This may be done using SESSIONs.

            session_start() ;
            $_SESSION['predefined'] = $predefined;
            session_write_c lose();
            header('Locatio n: first_page.php' );

            Then, in first_page.php, you get the predefined value back and place it
            into a POST value.

            session_start() ;
            <form action="second_ page.php" method="POST">
            <input type="hidden" name="predefine d" value="<?php echo
            $_SESSION['predefined'];?>">
            </form>

            Now, the value of 'predefined' is available to second_page.php as a
            $_POST value.

            $predefined = $_POST['predefined'];

            Does this help?

            -david-

            Comment

            • Alex Murphy

              #7
              Re: How to transfer the variable to next page?

              Thanks David, it is very useful for me. I never know PHP can do that.
              Thanks again.

              Comment

              • Chirag Shukla

                #8
                Re: How to transfer the variable to next page?


                Alex Murphy wrote:[color=blue]
                > The first page have the pre-define variable. How to transfer to next
                > php page?
                > Thanks[/color]

                Use Sessions or write text files in a temporary location. Sessions are
                better.

                Comment

                • Paul Lautman

                  #9
                  Re: How to transfer the variable to next page?

                  David Haynes wrote:[color=blue]
                  > Alex Murphy wrote:[color=green]
                  >> But... how to post a predefined variable?
                  >>[/color]
                  >
                  > The first step is to get php to send the predefined value to the web
                  > browser. This may be done using SESSIONs.
                  >
                  > session_start() ;
                  > $_SESSION['predefined'] = $predefined;
                  > session_write_c lose();
                  > header('Locatio n: first_page.php' );
                  >
                  > Then, in first_page.php, you get the predefined value back and place
                  > it into a POST value.
                  >
                  > session_start() ;
                  > <form action="second_ page.php" method="POST">
                  > <input type="hidden" name="predefine d" value="<?php echo
                  > $_SESSION['predefined'];?>">
                  > </form>
                  >
                  > Now, the value of 'predefined' is available to second_page.php as a
                  > $_POST value.
                  >
                  > $predefined = $_POST['predefined'];
                  >
                  > Does this help?
                  >
                  > -david-[/color]
                  But if he simply wants to carry a value from one page to the next and he is
                  doing it via a hidden field in a post, does he really need the session?


                  Comment

                  Working...