Results 1 to 6 of 6

Thread: pass variables between pages

  1. #1
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pass variables between pages

    i have a page first.php in this i have 7 veriables like $1, $2, $3, $4, $5, $6, $7. i have another page second.php i want to pass some variables from first.php to second.php.

    with out using the form submission.

    is there anyway.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You'r best bet would be to use either sessions, cookies, or by using the GET method (second.php?1=$1&2=$2...). If you were to use sessions, you could do something like the following:

    first.php
    Code:
    <?php
    session_start();
    
    $_SESSION['1'] = 'variable 1';
    $_SESSION['2'] = 'variable 2';
    
    //rest of code
    ?>
    Code:
    <?php
    session_start();
    
    echo $_SESSION['1'];
    echo '<br><br>';
    echo $_SESSION['2'];
    
    //rest of code
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks.

    i have link in first.php

    <a href="second.php?id=<?php echo $1; ?>">CLICK HERE </a>

    by this i can get the $1 variable in second.php

    like this.

    <a href="second.php?id=<?php echo $1; ?>&amp;two=<?php echo $2; ?>&amp ">CLICK HERE </a>

    am i rite....

    plz reply me the exact code for that GET method.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That is how you would send the variables to the second php page, yes. Then in the second php page; in order to extract those variables, you would want to do something like this:

    Code:
    <?php
    $1 = $_GET['id'];
    $2 = $_GET['two'];
    
    //and so on
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank you

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $1 is invalid, by the way. Must start with a letter. (Or, system variables use the reserved _ start, like $_GET.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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