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 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    GET and POST question

    If I have formsend.php, and I want to use method POST, what should I type on the address? Example: mysite.com/formsend.php?name=myname&login=password

    What should I type so it's POST ?

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $_POST is only for form information and cannot be used with the url bar ($_GET). Why would you want POST if its in the URL bar?
    |||||||||||||||||||||||||||||||||

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I have a remotely hosted form service and it says that it can only be runned through url bar. So how can I send it like it is POST ?

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll need to use $_GET then.
    |||||||||||||||||||||||||||||||||

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    so, what should I type the url? Give me example url line that sends code as $_POST or $_GET. Thanks

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I tried www.domain.com/formsend.php?name=myname&login=password&$_POST=1 but that didn't work

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    If you're using the url to send data you are not using post.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    Post

    kaisellgren: It seems from your last post that you're not fully understanding the $_POST/$_GET difference.

    Not to worry, here's how it works:

    if you put your variables into the URL bar like so:

    http://www.domain.com?number=100&fruit=apple&primate=human
    Then in the PHP, you can access the variables like so:

    PHP Code:
    print ("number = ".$_GET["number"]."<br>".
            
    "fruit= ".$_GET["fruit"]."<br>".
            
    "primate= ".$_GET["primate"]."<br>"); 
    This will print to a web browser like so:

    number = 100
    fruit = apple
    primate = human

    Conversely, if you wrote a form like so:

    Code:
    <form method="post" action="http://www.domain.com">
      <input type="text" name="number" value="100">
      <input type="text" name="fruit" value="apple">
      <input type="text" name="primate" value="human">
      <input type="submit">
    </form>
    Then you could access the variables in your PHP like so:

    PHP Code:
    print ("number = ".$_POST["number"]."<br>".
            
    "fruit= ".$_POST["fruit"]."<br>".
            
    "primate= ".$_POST["primate"]."<br>"); 
    Also, you can use $_REQUEST. This contains the variables in both $_GET and $_POST (don't know what happens if you have a post and a get variable of the same name, never had reason to try it!). If you use request, then it doesn't matter whether your data comes from a posted form or a URL bar.

    Use like so

    PHP Code:
    print ("number = ".$_REQUEST["number"]."<br>".
            
    "fruit= ".$_REQUEST["fruit"]."<br>".
            
    "primate= ".$_REQUEST["primate"]."<br>"); 
    Personally, I use $_REQUEST everywhere, unless I have a specific reason for using $_POST or $_GET (which is rare).
    Last edited by mlse; 01-07-2006 at 01:42 PM.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #9
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by kaisellgren
    I have a remotely hosted form service and it says that it can only be runned through url bar. So how can I send it like it is POST ?
    You need to give your form method = "get", that will put the form data in the address bar.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by mlse
    Also, you can use $_REQUEST. This contains the variables in both $_GET and $_POST (don't know what happens if you have a post and a get variable of the same name, never had reason to try it!). If you use request, then it doesn't matter whether your data comes from a posted form or a URL bar.
    $_REQUEST gets all of the $_GET, $_POST, and $_COOKIE fields. If there are two with the same name then the variables_order value in the php.ini file decides which to use.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    I learn something new every day!

    Very usefull "Ask Felgall" site too ...
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

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