1

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!

seanmichael
  • 25
  • 1
  • 6
  • Read the post of tom http://stackoverflow.com/questions/4586835/how-to-pass-extra-variables-in-url-with-wordpress – Dneiz Sep 01 '13 at 14:42

4 Answers4

7

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.

Basic
  • 26,321
  • 24
  • 115
  • 201
apnorton
  • 2,430
  • 1
  • 19
  • 34
2

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.

mario
  • 144,265
  • 20
  • 237
  • 291
1

Have you tried to remove spaces in your link?

<a href="TESTGET.php?id=5">ID</a>
Vertigo
  • 2,714
  • 1
  • 22
  • 24
1

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

Leo Haris
  • 561
  • 2
  • 8