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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gobo
Forum Newbie
Posts: 9
Joined: Sun Dec 28, 2003 5:29 pm

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

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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).
Post Reply