...

View Full Version : grabbing a variable from the URL



misterx
02-22-2003, 06:43 PM
I'm putting together a little script that I would like to display a message if a certain variable is defined. This is effectively what it looks like right now:


if ("any of the form fields are not filled") {
header("Location: file.php?notfilled=1");
exit;
}

and then down where I want the message to show up...

if (!empty($notfilled)) {
print("You did not fill in one or more of the required fields.\n");
}



And that doesn't work. If I navigate to file.php?notfilled=1 it still won't print that message. And I use this method on other pages!The only thing different about where I'm coding the current script vs. my other ones is this new one is on a Windows server, the other ones are on FreeBSD. Is that what's making the difference?

misterx
02-22-2003, 06:58 PM
Ok, so I thought I had found the answer to my problem. Seems like I should be able to declare the variable with:

$notfilled = $_GET["notfilled"];
And THEN use $notfilled in an if statement. However as soon as I put that declaration in I get this error message:

PHP Notice: Undefined index: notfilled in C:\Inetpub\virtual\w-link.net\submit_shop.php on line 19

So now what am I supposed to think?!

Nightfire
02-22-2003, 08:00 PM
This bit confuses me




if (!empty($notfilled)) {
print("You did not fill in one or more of the required fields.\n");
}


You have it saying:

if notfilled is not empty, print the message... is that what it's meant to do? :confused: If not, take the ! away

Newer versions of PHP use $_GET, older versions will use $HTTP_GET_VARS

misterx
02-22-2003, 08:19 PM
Well the if statement is irrelevant at this point. Regardles of how I set that up, this line:

$notfilled = $_GET["notfilled"];

Causes the above error message. And I did just try it the long way with $HTTP_GET_VARS to no avail.

x_goose_x
02-23-2003, 02:38 AM
I don't know what is causing this and realize that this isn't solving any problem, just avoiding it, but what about trying another approach. Worth giving a shot.

what about changing the line:

header("Location: file.php?notfilled=1");

to:

header("Location: file.php?1");

then use:

$notfilled = $_SERVER["QUERY_STRING"]);

Since it's only one field this will work. When you need more you'll have to figure out what's going wrong. Hope it helps you somewhat.

Jesh
02-23-2003, 06:40 PM
Yes thats probably the reason.

Instead of Location: file.php?a=a, try Location: http://blah/file.php?a=a

If you are on a windows server, your PC, just open php.ini and turn on globals registering, since it is only you that can view "localhost"...there should not be any security problems...

If it isn't your pc, do it through htaccess. Just copy that line on to htaccess and try changing On to 1 or true..

Good Luck

Jesh



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum