variable vs URL

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

    variable vs URL

    Hi,

    It's probably very easy, but I cannot find my mistake:

    page1.php

    <?php
    echo "<a href=page2.php? vartrans=5342>C lic</a>";
    ?>

    page2.php

    <?php
    echo "$vartrans" ;
    ?>

    When I click on the link on page 1, page 2 appears on the screen but with
    the following error message:

    Notice: Undefined variable: vartrans in c:\program
    files\easyphp1-7\www\page2.php on line 2

    What's my mistake?

    I use php 4.3.3.

    Thank you vm in advance for your help

    Lc



  • Pedro Graca

    #2
    Re: variable vs URL

    Lc wrote:[color=blue]
    > What's my mistake?
    >
    > I use php 4.3.3.[/color]

    You're relying on register_global s being on, and they're off.

    Use the superglobal array $_GET instead.

    <?php // page2.php
    echo "{$_GET['vartrans']}";
    ?>

    read all about it at
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.



    --
    USENET would be a better place if everybody read: | to email me: use |
    http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
    http://www.netmeister.org/news/learn2quote2.html | header, textonly |
    http://www.expita.com/nomime.html | no attachments. |

    Comment

    • Matthias Scheller

      #3
      Re: variable vs URL

      Lc schrieb:[color=blue]
      > Hi,
      >
      > It's probably very easy, but I cannot find my mistake:
      >
      > page1.php
      >
      > <?php
      > echo "<a href=page2.php? vartrans=5342>C lic</a>";
      > ?>
      >
      > page2.php
      >
      > <?php
      > echo "$vartrans" ;
      > ?>
      >
      > When I click on the link on page 1, page 2 appears on the screen but with
      > the following error message:
      >
      > Notice: Undefined variable: vartrans in c:\program
      > files\easyphp1-7\www\page2.php on line 2
      >
      > What's my mistake?
      >
      > I use php 4.3.3.
      >
      > Thank you vm in advance for your help
      >
      > Lc
      >
      >
      >[/color]
      Use better

      <?phP
      echo $_REQUEST["vartrans"];
      ?>

      to have both, GET and POST method covered

      Comment

      Working...