Jump to content

Archived

This topic is now archived and is closed to further replies.

jmilane

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
A simple example.

[code=php:0]
<?php

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

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

Share this post


Link to post
Share on other sites
http://www.somewhere.com/go_here.php?id=8972

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

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=109415.msg440924#msg440924 date=1159193906]
A simple example.

[code=php:0]
<?php

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

This is all within one page but should give you the idea.
[/quote]

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...

Share this post


Link to post
Share on other sites
[quote author=jmilane link=topic=109415.msg440932#msg440932 date=1159194181]
[quote author=thorpe link=topic=109415.msg440924#msg440924 date=1159193906]
A simple example.

[code=php:0]
<?php

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

This is all within one page but should give you the idea.
[/quote]

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...
[/quote]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.