Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    grabbing a variable from the URL

    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:
    PHP Code:
    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?

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, so I thought I had found the answer to my problem. Seems like I should be able to declare the variable with:
    PHP Code:
    $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?!
    Last edited by misterx; 02-22-2003 at 07:34 PM.

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    This bit confuses me

    PHP Code:

    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? If not, take the ! away

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

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Registered User
    Join Date
    Feb 2003
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •