seanmichael
seanmichael

Reputation: 25

Sending information through URL using $_GET not working

So I'm trying to do something extremely simple, and after reading through forums, and researching on google I still can't figure out why this is not working. But this is mostly like because I'm still a very much noobie programmer. I'm trying to send information through a url, and having a script pick it up using the $_GET super global.

Here's the link code, in a file called TESTFORM.php:

<p>
Here's a link:
<a href = "TESTGET.php?id = 5">ID</a>
</p>

This is the TESTGET.php script:

<?php
    if (isset($_GET['id']))
        echo 'it is set<br />';
    else
        echo 'it is not set<br />';
?>

This yields in a "It is not set" appearing on the page every time. Any thoughts? Are there ghosts in my computer ruining my code? Thanks for taking the time to read through this! Happy coding!

Upvotes: 1

Views: 4100

Answers (4)

apnorton
apnorton

Reputation: 2440

I'm no PHP programmer, but I do know from HTML that computers (especially file names) don't "like" spaces. Try removing the spaces in the id = 5 code.

Upvotes: 7

Leo Haris
Leo Haris

Reputation: 561

Code seems fine at a glance, have you tried removing the spaces in ?id = 5 to ?id=5

Upvotes: 1

Vertigo
Vertigo

Reputation: 2746

Have you tried to remove spaces in your link?

<a href="TESTGET.php?id=5">ID</a>

Upvotes: 1

mario
mario

Reputation: 145482

Your problem is the extraneous space here around the URL parameters:

<a href = "TESTGET.php?id = 5">ID</a>

That will result in PHP seeing the parameter as $_GET["id_"]. The space gets converted into an underscore.

It's always best to use var_dump($_GET); or var_dump($_REQUEST) when you run into such problems. Secondarily it is sometimes helpful to get rid of isset in such cases. Albeit you have a custom error message in place of the language notices intended just for that.

Upvotes: 2

Related Questions