$_GET variable question

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

    $_GET variable question

    I have a file.php in which a created dynamic hypertext links and send a
    variable $row[0]

    echo "<td><a href='modify_re quest.php?$row[0]'>$row[0]</a></td>";

    I can see in the url on modify_request. php the variable value.

    But I can't get it in another variable in modify_request. php

    here is a simple example of what I am trying to do with file1
    =============== =============

    <?php
    $var1 = 2;
    echo "<a href='get_it.ph p?$var1'>click here</a>";
    ?>

    and in file2 I try to use the variable $var2
    =============== ===============

    <?php

    $var2= $_GET[var1];

    print "$var2";

    ?>

    =============== ===============
    in that example, it doesn't print $var2...

    can someone tell me what misses to make this work please?


  • Kim André Akerø

    #2
    Re: $_GET variable question

    stephane wrote:
    [color=blue]
    > I have a file.php in which a created dynamic hypertext links and send
    > a variable $row[0]
    >
    > echo "<td><a href='modify_re quest.php?$row[0]'>$row[0]</a></td>";
    >
    > I can see in the url on modify_request. php the variable value.
    >
    > But I can't get it in another variable in modify_request. php
    >
    > here is a simple example of what I am trying to do with file1
    > =============== =============
    >
    > <?php
    > $var1 = 2;
    > echo "<a href='get_it.ph p?$var1'>click here</a>";
    > ?>
    >
    > and in file2 I try to use the variable $var2
    > =============== ===============
    >
    > <?php
    >
    > $var2= $_GET[var1];
    >
    > print "$var2";
    >
    > ?>
    >
    > =============== ===============
    > in that example, it doesn't print $var2...
    >
    > can someone tell me what misses to make this work please?[/color]

    Since you're not using a name=value combination, it isn't assigned to
    any key in the $_GET array. What you rather need to do in the example,
    is:

    =============== =============== =====
    <?php
    // file1

    $var1 = 2;
    echo "<a href=\"get_it.p hp?var1=".$var1 ."\">click here</a>";
    ?>
    =============== =============== =====
    <?php
    // file2

    $var2 = $_GET["var1"];
    echo $var2;
    ?>
    =============== =============== =====

    --
    Kim André Akerø
    - kimandre@NOSPAM betadome.com
    (remove NOSPAM to contact me directly)

    Comment

    • milahu

      #3
      Re: $_GET variable question

      You also could get the whole string behind the "?" from
      $_SERVER['QUERY_STRING']

      Comment

      • Duderino82

        #4
        Re: $_GET variable question

        a little tip that is not actually the problem here but it migth com in
        handy in the future...whenev er you use the $_GET into an if statement
        remember to use the isset() function.


        if (isset($_GET['var']))

        is better then:


        if ($_GET['var'])

        they should both work but the second may sometime give you some
        problems...

        Comment

        Working...