SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this work?

    I see most everyone uses:
    $date = $_POST['date'] ;

    But this also works too:
    $_POST['date'] ;

    Why use the first when the second seems to do the same thing?
    Opportunity favors the prepared mind.

  2. #2
    SitePoint Evangelist Will Kelly's Avatar
    Join Date
    May 2005
    Location
    London
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Copying the post variable 'date' to a local variable. Can make it easier to type to or to do future processing on it. Hardly makes a difference.

    If there's any legacy code in an app that requires register_globals on this could also be used to get round that.

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Will says + if you decide to use GET or the date arrives by some other method ( from db etc ) at some point in the future you only have one change to make.

  4. #4
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and what is the difference between post and get please?

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    post = submitted from within the browser
    get = submitted through the URL
    sessions = stored on the server
    cookies = stored on the client

  6. #6
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i will search more about that :-) thanks for your short and sweet info

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Also the advantage of registering 'simple' variables from the different globals is that you can do all processing, error checking etc once and not each time you use it eg:
    PHP Code:
    # this as an example.....
    $datestripslashes(htmlentities(trim($_POST['date'])));
    # could then be used

    echo $date;

    mysql_query("select * from table where '$date' = date"); 
    Instead of

    PHP Code:
    $datestripslashes(htmlentities(trim($_POST['date'])));
    # could then be used

    echo stripslashes(htmlentities(trim($_POST['date'])));

    mysql_query("select * from table where '"mysql_real_escape_string($_POST['date'] . "' = date");

    #etc..... 
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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