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 8 of 8
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    getting querystring data in php?

    hello!

    how can i request data from the query string in php??

    thanks in advance for your time!
    -Ken

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use $_GET, for instance if your querystring is:
    PHP Code:
    www.domain.com?id=bob&level=admin 
    You can access the qs values via $_GET['id'] and $_GET['admin'].

    Alternatively, if you're just wanting to grab the entire querystring as a string you can do so using $_SERVER['QUERY_STRING'].

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    // If using GET method
    $stringl $_GET["field_name"];
    // If using POST method
    $stringl $_POST["field_name"]; 

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, is it the same thing for requesting submitted form data?


    thanks again for al your help guys!

    -SiX

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    hmm, i seem to be getting an error when I try to use:

    $username = $_GET["username"];

    gives me:
    Notice: Undefined index: username in C:\Apache Group\Apache2\htdocs\national\admin\test.php on line 3

    am i missing something?

    -SiX

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're using the GET form method then it should be the same. If you want to use the POST form method, same thing but use $_POST['username'] instead.

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, but i'm getting an error for some reason when i do it, as i posted right above your post, do you have any idea what i've done wrong?

    thanks again!

    -SiX

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should only be getting that error if the data wasn't properly passed from one page to the other, it's basically saying that it can't find a variable in $_GET/$_POST (whichever you're using) with the name specified.

    Which method are you using to submit your data?


  •  

    Posting Permissions

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