help passing variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Northrop
    New Member
    • Jan 2007
    • 67

    help passing variables

    test.php:

    <?php
    $d=$_GET['data'];
    echo $d;
    ?>

    when i go to
    www....com/test.php?data=1
    nothing happens.

    I have read a few articles on passing variables through the url and i believe this is the right syntax. Anyone see something im doing wrong?

    Thanks
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Syntax look OK. 'Nothing happens' is not much help. Do you go to the page you expect

    Comment

    • devsusen
      New Member
      • Feb 2007
      • 136

      #3
      Hi,

      it should show 1 in the page. If u like to do something else u need to write the code instead of writting echo $d;
      Originally posted by Shawn Northrop
      test.php:

      <?php
      $d=$_GET['data'];
      echo $d;
      ?>

      when i go to
      www....com/test.php?data=1
      nothing happens.

      I have read a few articles on passing variables through the url and i believe this is the right syntax. Anyone see something im doing wrong?

      Thanks
      susen

      Comment

      • Shawn Northrop
        New Member
        • Jan 2007
        • 67

        #4
        thats the problem, it does not show 1

        if i change the code to:
        $d = $_GET['data'];
        echo ("hi" . $d); and go to www...com/test.php?$data= 1; it prints:

        Hi

        However if i change
        $d = $_GET['data'];
        to
        $d = 1;

        Then it will print
        Hi 1, like expected

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Your posted code is inconsistent! Your first post named the url variable data
          Code:
          data.www....com/test.php?data=1
          In the second you name it $data
          Code:
          www...com/test.php?$data=1;
          The dollar should not be there

          Comment

          • devsusen
            New Member
            • Feb 2007
            • 136

            #6
            Hi,

            the url should be www....com/test.php?data=1 not the 2nd one. Try $_REQUEST['data']. But I still don't found any problem with ur code.

            susen

            Comment

            Working...