Results 1 to 8 of 8

Thread: When to use $_REQUEST and when to use $_POST

  1. #1

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616

    When to use $_REQUEST and when to use $_POST

    I am assuming that $_REQUEST will grab the variable out of the address bar/link and that $_POST is used when the method of the form is "post".

    Are my assumptions correct or am I wrong?

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  2. #2

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    For example, am I using this correctly:

    $query = mysql_query("select * from abMembers where id='$_REQUEST[\\'id\\']'");

    id will be passed via a link: http://whatever.com/?id=15

    Is using request like that correct or do I need to use something else?
    Last edited by cpradio; Jun 6th, 2002 at 09:09 AM.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3
    scoutt
    Guest
    $_REQUEST is the same as $_GET & $_POST, I mean it does both. I tend to use $_REQUEST as I had problems with $_POST and never could get the variable to show.

  4. #4

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Okay, so I can replace all _POST with _REQUEST?

    Also will my above example work?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5
    scoutt
    Guest
    same goes with this

    PHP Code:
    $query mysql_query("select * from abMembers where id='".$_REQUEST["id"]."'"); 

  6. #6
    Member
    Join Date
    Apr 2002
    Posts
    52
    Variables are passed from one page to another using either the POST method (within the http header string, not visible in the address bar) OR GET (within the URL)

    In PHP both methods result in the variables being present as globals to the action script file. In ASP and I think JSP, POST and GET have different functions to retreive the variable values, and GET variables can't be taken from the POST function and vice-versa.
    Here's the php manual's definition of $_REQUEST:
    An associative array consisting of the contents of $_GET, $_POST, $_COOKIE, and $_FILES. (http://www.php.net/manual/en/reserved.variables.php)

    In other words, $_REQUEST carries all the globally available variables.

    HTH.

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by thexchord
    In other words, $_REQUEST carries all the globally available variables.
    Wrong. It does not contain $_SERVER or $_SESSION.

    I, personally, always use $_REQUEST as well.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Member
    Join Date
    Apr 2002
    Posts
    52
    Originally posted by The Hobo


    Wrong. It does not contain $_SERVER or $_SESSION.

    I, personally, always use $_REQUEST as well.
    That's my alternate ego posting an errata.






Posting Permissions

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



Click Here to Expand Forum to Full Width