$_GET AND $_POST in harmony !

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default $_GET AND $_POST in harmony !

    I've been struggling with this since I started writing web apps. I cannot
    wrap my brain around a universal function for handling GET AND POST data.

    I have written several functions to handle but none really satisfy. I
    usually end up going back to $_GET['var_name'] (or POST) especially when it
    comes to handling databsae inserts and updates.

    Does anyone know where or have code that can give me a good foundation on
    writing a 'semi-universal' function/class to handle post and get requests.


    Thanks in advance.....

    - j


    Jeff Guest

  2. Similar Questions and Discussions

    1. Accepting variables via $_GET and $_POST in same script ?
      usenet@isotopeREEMOOVEmedia.com wrote: Use $_SERVER to determine what HTTP request method was used to access your PHP script. ...
    2. #25231 [Bgs]: Strange $_GET/$_POST Behaviour
      ID: 25231 Updated by: sniper@php.net Reported By: tim at zero-interactive dot com Status: Bogus Bug Type: ...
    3. #25231 [Opn->Bgs]: Strange $_GET/$_POST Behaviour
      ID: 25231 Updated by: sniper@php.net Reported By: tim at zero-interactive dot com -Status: Open +Status: ...
    4. #25231 [Opn->Fbk]: Strange $_GET/$_POST Behaviour
      ID: 25231 Updated by: iliaa@php.net Reported By: tim at zero-interactive dot com -Status: Open +Status: ...
    5. #25231 [NEW]: Strange $_GET/$_POST Behaviour
      From: tim at zero-interactive dot com Operating system: Win2K Pro PHP version: 4.3.2 PHP Bug Type: Variables related Bug...
  3. #2

    Default Re: $_GET AND $_POST in harmony !

    Since in theory (and also in practice;) both can be set at the same
    time you will have to decide which to chose at some point.
    I use something like
    $name = (isset($_GET['name'])) ? $_GET['name'] :
    (isset($_POST['name'])) ? $_POST['name'] : "no name entered!";
    (I hope I didn't forget any brackets now:)

    Regards,
    johannes

    johannes m.r. Guest

  4. #3

    Default Re: $_GET AND $_POST in harmony !

    Jeff wrote:
    > I've been struggling with this since I started writing web apps. I
    > cannot wrap my brain around a universal function for handling GET AND
    > POST data.
    >
    > I have written several functions to handle but none really satisfy. I
    > usually end up going back to $_GET['var_name'] (or POST) especially
    > when it comes to handling databsae inserts and updates.
    >
    > Does anyone know where or have code that can give me a good
    > foundation on writing a 'semi-universal' function/class to handle
    > post and get requests.
    >
    >
    > Thanks in advance.....
    >
    > - j
    You can use $_REQUEST to retrieve form variables whether they were sent via
    POST or GET.


    Nathan


    Nathan Gardiner Guest

  5. #4

    Default Re: $_GET AND $_POST in harmony !

    Thanks Nathan,.....
    I had read something about that a few releases ago but was under the
    impression that REGISTER_GLOBALS would need to be enabled....my bad !!

    I have been testing with it over the past week but I wasn't sure if this was
    the ultimate or 'recommended' approach to coding.....

    anywho....Thanks again !!



    "Nathan Gardiner" <nate@nate.id.au> wrote in message
    news:40bdd08f$0$326$c3e8da3@news.astraweb.com...
    > Jeff wrote:
    > > I've been struggling with this since I started writing web apps. I
    > > cannot wrap my brain around a universal function for handling GET AND
    > > POST data.
    > >
    > > I have written several functions to handle but none really satisfy. I
    > > usually end up going back to $_GET['var_name'] (or POST) especially
    > > when it comes to handling databsae inserts and updates.
    > >
    > > Does anyone know where or have code that can give me a good
    > > foundation on writing a 'semi-universal' function/class to handle
    > > post and get requests.
    > >
    > >
    > > Thanks in advance.....
    > >
    > > - j
    >
    > You can use $_REQUEST to retrieve form variables whether they were sent
    via
    > POST or GET.
    >
    >
    > Nathan
    >
    >

    Jeff Guest

  6. #5

    Default Re: $_GET AND $_POST in harmony !

    "Jeff" <x_cipher@hotmail.com> wrote in message
    news:c9ilfv026a6@enews1.newsguy.com...> I've been struggling with this since
    I started writing web apps. I cannot
    > wrap my brain around a universal function for handling GET AND POST data.
    >
    > I have written several functions to handle but none really satisfy. I
    > usually end up going back to $_GET['var_name'] (or POST) especially when
    it
    > comes to handling databsae inserts and updates.
    >
    > Does anyone know where or have code that can give me a good foundation on
    > writing a 'semi-universal' function/class to handle post and get requests.

    Sorry, it's it's been a long day so I can't figure out where this is off
    topic or not... I just extract everything so I don't have to worry about
    whether or not it's a "post" or a "get" variable. I put the following
    commands at the top of my scripts:

    extract ($_POST);
    extract ($_GET);

    Once that's been done, an input field named "fred" for example is
    accessible quite simply as "$fred", whether it came back via a GET or a
    POST. It's my responsibility to ensure that I don't overwrite anything by
    executing those commands, but I've never had to think much about this... I
    know what my variables are! I wouldn't even mention this except that I've
    only recently realized while reviewing someone else's code that this
    approach is not widely known. It may not be appropriate for your
    application, but just in case...

    Peter




    Peter Pagé Guest

  7. #6

    Default Re: $_GET AND $_POST in harmony ! Thanks

    Peter Pagé a schtroumphé:
    > "Jeff" <x_cipher@hotmail.com> wrote in message
    > news:c9ilfv026a6@enews1.newsguy.com...> I've been struggling
    > with this since
    > I started writing web apps. I cannot
    >> wrap my brain around a universal function for handling GET
    >> AND POST data.
    >>
    >> I have written several functions to handle but none really
    >> satisfy. I usually end up going back to $_GET['var_name']
    >> (or POST) especially when
    > it
    >> comes to handling databsae inserts and updates.
    >>
    >> Does anyone know where or have code that can give me a good
    >> foundation on writing a 'semi-universal' function/class to
    >> handle post and get requests.
    >
    >
    > Sorry, it's it's been a long day so I can't figure out where
    > this is off
    > topic or not... I just extract everything so I don't have to
    > worry about
    > whether or not it's a "post" or a "get" variable. I put the
    > following commands at the top of my scripts:
    >
    > extract ($_POST);
    > extract ($_GET);
    >
    > Once that's been done, an input field named "fred" for
    > example is accessible quite simply as "$fred", whether it came
    > back via a GET or a
    > POST. It's my responsibility to ensure that I don't
    > overwrite anything by executing those commands, but I've never
    > had to think much about this... I
    > know what my variables are! I wouldn't even mention this
    > except that I've only recently realized while reviewing
    > someone else's code that this
    > approach is not widely known. It may not be appropriate for
    > your application, but just in case...
    >
    > Peter
    I don't know if your post has been usefull for the OP; it is for
    me.

    I'm building a php app with about 30 complex forms and that
    trick will save me hours of typing (and typos). I tried it
    today and it works perfectly.

    I wonder why i did not find this before.

    Thanks again.


    --
    mv cso /dev/null
    Marc Nadeau# La Pagerie /* [url]http://www.pagerie.com[/url] */
    Marc Nadeau Guest

  8. #7

    Thumbs down Re: $_GET AND $_POST in harmony !

    please explain this.....................
    Abubakar Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139