Jump to content


Photo

How do I pass a variable via URL and then have it brought into a script?


  • Please log in to reply
4 replies to this topic

#1 jmilane

jmilane
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 September 2006 - 02:13 PM

I want to send people a link that, when clicked, will open a php page which searches based on an id number.

The id number will have to be appended to the end of the url.

How do I set this up? Do I have to take the id number off of the url in the processing script and then incorporate it into a query?

I know this probably has to do with the "?" in php URLs - but I am extremely new.

Thank you.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 02:18 PM

A simple example.

<?php

  if (isset($_GET['id'])) {
    echo "You clicked foo";
  } else {
    echo "<a href='?id=foo'>foo</a>";
  }
?>

This is all within one page but should give you the idea.

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 September 2006 - 02:20 PM

http://www.somewhere...ere.php?id=8972

As a very simple example:
<?php
// go_here.php
if (isset($_GET['id'])) {
    $id = $_GET['id']; // retrieve id value passed by URL
} else {
    exit();
}
... your code follows ...

Legend has it that reading the manual never killed anyone.
My site

#4 jmilane

jmilane
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 September 2006 - 02:23 PM

A simple example.

<?php

  if (isset($_GET['id'])) {
    echo "You clicked foo";
  } else {
    echo "<a href='?id=foo'>foo</a>";
  }
?>

This is all within one page but should give you the idea.


So the $_GET var would be passed just in the url... like www.mysite.com/search?id=foo

But then the file itself would simply be named www.mysite.com/search.php?

And then the $_GET var would be whatever immediately follows the ? (in this case 'id'?)

Thanks! Even if I am wrong...

#5 mendoz

mendoz
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts

Posted 25 September 2006 - 05:28 PM

A simple example.

<?php

  if (isset($_GET['id'])) {
    echo "You clicked foo";
  } else {
    echo "<a href='?id=foo'>foo</a>";
  }
?>

This is all within one page but should give you the idea.


So the $_GET var would be passed just in the url... like www.mysite.com/search?id=foo

But then the file itself would simply be named www.mysite.com/search.php?

And then the $_GET var would be whatever immediately follows the ? (in this case 'id'?)

Thanks! Even if I am wrong...


It will be named www.mysite.com/search.php,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users