Page 1 of 1

Page Query Help => page.php?q=...

Posted: Sun Dec 28, 2003 7:21 pm
by gobo
Hi all!

I'm after a little help here;

page.php?q=xxxxx

i have page.php and i require a variable (q) to be filled by the URL, which ofcourse other pages can pass information from, e.g. search.php passes "hello" to page.php?q=hello .

I just want to detect what is in (q).

The thing is I have scraped to a halt at php.net, when I thought I was on the right trail with $_GET['q'] ... q being my variable, but all seems confusing, as when there is no [q=xxxx] in the URL, it wormies out with "Notice: Undefined index: q in C:\program files\Apache Group\Apache2\htdocs\TMP4kl57qmu9s.php on line 125"

I have tried

if ($_GET['q'] == null) {
} else {
echo $_GET['q'];
}

To begin with I was under the impression that $_GET['q']; was actually the variable $q ... but no.

It would be fantastic if you could help me out with any suggestions!

Gobo

Posted: Sun Dec 28, 2003 7:34 pm
by McGruff
If register globals are on (yuk) $_GET['q'] is automatically added to the global scope as $q - hence $q == $_GET['q'].

If there is no "q" var in the query string $_GET['q'] is not set. Try:

Code: Select all

if(!isset($_GET['q']))
{
    ..etc
}
If a $var == null, it IS set (to null, obviously).