...

View Full Version : GET and POST question



kaisellgren
01-07-2006, 12:42 AM
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 ?

Yusayoh
01-07-2006, 01:58 AM
$_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?

kaisellgren
01-07-2006, 02:02 AM
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 ?

Yusayoh
01-07-2006, 02:57 AM
You'll need to use $_GET then.

kaisellgren
01-07-2006, 12:27 PM
so, what should I type the url? Give me example url line that sends code as $_POST or $_GET. Thanks

kaisellgren
01-07-2006, 12:55 PM
I tried www.domain.com/formsend.php?name=myname&login=password&$_POST=1 but that didn't work

marek_mar
01-07-2006, 01:08 PM
If you're using the url to send data you are not using post.

mlse
01-07-2006, 02:35 PM
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:



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:



<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:



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



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).

NancyJ
01-07-2006, 04:27 PM
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.

felgall
01-07-2006, 10:54 PM
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.

mlse
01-09-2006, 12:34 PM
I learn something new every day! :thumbsup:

Very usefull "Ask Felgall" site too ...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum