How to Use HTML Parameters in PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xmp333@yahoo.com

    How to Use HTML Parameters in PHP?

    Hi,

    I'm trying to create a page where clicking on a link will go to a php
    page and pass it parameters so it can determine which link was
    clicked. I don't want to use any client side scripting for this, so
    making the link act as a submit button via javascript won't do.

    Unfortunately, this isn't working. Here is the sample code.

    First the page with the links:

    <html>
    <body>
    <a href="dest.php? link=Link1">Lin k 1</a>
    <a href="dest.php? link=Link2">Lin k 2</a>
    </body>
    </html>

    And the php script:

    <html>
    <body>
    <? if ($_GET['Link1'])
    echo "Link 1 Clicked";
    else
    echo "Link 2 Clicked"; ?>
    </body>
    </html>


    In the above script, also tried $_POST, but php is not picking up the
    variables. What am I doing wrong?


    Thanks.
  • Ed Seedhouse

    #2
    Re: How to Use HTML Parameters in PHP?

    On Sat, 03 Jan 2004 20:26:08 -0800, xmp333 wrote:
    [color=blue]
    > I'm trying to create a page where clicking on a link will go to a php
    > page and pass it parameters so it can determine which link was
    > clicked. I don't want to use any client side scripting for this, so
    > making the link act as a submit button via javascript won't do.
    > Unfortunately, this isn't working. Here is the sample code.
    > First the page with the links:
    >
    > <html>
    > <body>
    > <a href="dest.php? link=Link1">Lin k 1</a>
    > <a href="dest.php? link=Link2">Lin k 2</a>
    > </body>
    > </html>[/color]

    So clicking on either link will send a value to the action page.
    That value will be in the variable "link".
    [color=blue]
    > And the php script:
    >
    > <html>
    > <body>
    > <? if ($_GET['Link1'])[/color]

    There won't be anything in there because you didn't pass a variable
    named 'Link1' you passed a variable named 'link'.

    The paramater is passed as "link" not as "Link1" or "Link2". The
    value of $_GET['link'] will contain either "Link1" or "Link2"
    depending on what link was clicked.

    The value of $_GET['Link1'] will always be null the way you wrote the
    code.

    Ed

    Comment

    • Dan Tripp

      #3
      Re: How to Use HTML Parameters in PHP?

      Ed Seedhouse wrote:
      [color=blue]
      > On Sat, 03 Jan 2004 20:26:08 -0800, xmp333 wrote:
      >
      >[color=green]
      >>I'm trying to create a page where clicking on a link will go to a php
      >>page and pass it parameters so it can determine which link was
      >>clicked. I don't want to use any client side scripting for this, so
      >>making the link act as a submit button via javascript won't do.
      >>Unfortunately , this isn't working. Here is the sample code.
      >>First the page with the links:
      >>
      >><html>
      >><body>
      >><a href="dest.php? link=Link1">Lin k 1</a>
      >><a href="dest.php? link=Link2">Lin k 2</a>
      >></body>
      >></html>[/color]
      >
      >
      > So clicking on either link will send a value to the action page.
      > That value will be in the variable "link".
      >
      >[color=green]
      >>And the php script:
      >>
      >><html>
      >><body>
      >><? if ($_GET['Link1'])[/color]
      >
      >
      > There won't be anything in there because you didn't pass a variable
      > named 'Link1' you passed a variable named 'link'.
      >
      > The paramater is passed as "link" not as "Link1" or "Link2". The
      > value of $_GET['link'] will contain either "Link1" or "Link2"
      > depending on what link was clicked.
      >
      > The value of $_GET['Link1'] will always be null the way you wrote the
      > code.
      >
      > Ed[/color]


      You'd probably want to do something in your script like:

      == start ========
      <html>
      <body>
      <?
      if ($_GET['link']=="Link1"){
      echo "Link 1 Clicked";
      } else {
      echo "Link 2 Clicked";
      }
      ?>
      </body>
      </html>
      == end =========

      If you have more than two links, it'd be good to use a switch statement.


      Regards,

      - Dan
      dantripp.com

      Comment

      Working...