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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2002
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query Strings - detecting and accessing

    Can any one tell me how to access a query string and how to test if it exists?

    I know about using $_SERVER['QUERY_STRING'] but I want to just get the value at the end of the query string

    eg - page.php?id=2 - just want the "2".

    I am also having problems checking to see if the querystring exists in the first place. This is the code I have so far. If I manually append the query string in the address bar, then it works fine, jumps to the "else" statement etc. But without it it just fails.

    $memid = $_SERVER['QUERY_STRING'];

    if (!isset($memid))
    {
    printf("no query string");
    }
    else
    {
    printf($memid);
    }

    Thanks
    WillowFae

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You know you can access the querystring variables using:

    $_GET[id]

    (In the case of page.php?id=2)

    This will give you the "2".

    Then you can see if it exists using:

    PHP Code:

    IF (!isset($_GET[id])){
    echo 
    "id = $_GET[id]";
    } else {
    echo 
    "No id";

    Other than that I don't really understand what you are asking.

    http://www.php.net/manual/en/reserve....variables.get

  • #3
    New Coder
    Join Date
    Nov 2002
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bingo! No, that's fine, that was exactly what I was asking.

    Thanks a lot

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad i could be of help


  •  

    Posting Permissions

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