Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry passing values between pages

    I have three pages.
    one.php
    <form action="second.php" method="post">
    <input type="text" name="txt">
    <input type="submit" value="submit">
    </form>

    second.php
    <?php
    $err = $_Post['txt']; // from one.php

    if($err == 1)
    {
    $errVal = 1; ?>
    <script>
    location.href = "third.php"
    </script>

    <?php }
    else
    {
    echo $errVal;
    }

    ?>


    third.php
    <?php
    echo $errVal; // from second.php
    ?>

    if the text value from one.php is 1, then automatically that should be redirected to third.php and should carry the variable ($errVal) value to third.php from second.php. How can I achieve this. I am new to this php!. Thanks in advance.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You can use the GET method, which allows you to carry variables in URLs:

    one.php
    PHP Code:
    <form action="second.php" method="post">
    <
    input type="text" name="txt">
    <
    input type="submit" value="submit">
    </
    form
    second.php
    PHP Code:
    <?php
    $err 
    $_Post['txt']; // from one.php

    if($err == 1)
    {
    $errVal 1;
    header('Location: third.php?err=1'); // This will be transfered to third.php
    }
    else
    {
    echo 
    $errVal;
    }

    ?>

    third.php
    PHP Code:
    <?php
    echo $_GET['err']; // $_GET holds all URL variables
    ?>
    This explains it better.

  • Users who have thanked Mwnciau for this post:

    sesc (08-30-2007)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much. This is working fine for me!

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    you could use php sessions... then you can use it on any page aslong as session_start() is at the top of the page.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •