Click to See Complete Forum and Search --> : How does Forms pass var to PHP?
poolwin2001
March 11th, 2005, 02:15 AM
How do forms pass info to php source files?
for eg:
<html>
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
</html>
How does the form pass the name and message to sendmail.php?
Can we do it manually,i.e without HTML form?
say:sendmail.php?name='blah'&message='blahblahblah'
Thanks in advance
P.S:this is for creating an auto login script.
blueday54555
March 11th, 2005, 06:04 AM
your sendmail.php should look like that
<?php
$email=$_POST['email'];
$message=$_POST['message'];
echo $email."<br>".$message;
?>if you have something like
test.php?name='blah'&message='blahblahblah'
than you have to use _GET
<?php
$email=$_GET['email'];
$message=$_GET['message'];
echo $email."<br>".$message;
?>
in your case the _POST method is the right one !
bigBA
March 11th, 2005, 07:15 AM
and if you are not sure, or it is regardless if the variable comes into your script via get/post/cookie then you also can use $_REQUEST...
poolwin2001
March 11th, 2005, 08:21 AM
I was not asking how to get the output from a form but how to output to a php what would have come from a script.
apparently
sendmail.php?name=blah&message=blahblahblah
works
NOTE:no qoutes!!
Thanks anyway
blueday54555
March 11th, 2005, 08:50 AM
Now I would say, if you ask some question and two people answer it nearly the same way, than something is wrong with your question :)
bigBA
March 11th, 2005, 09:07 AM
Now I would say, if you ask some question and two people answer it nearly the same way, than something is wrong with your question :)
you said it :)
so, yeah.
you got two ways: either appending parameters to the url of the script -> the GET method.
HTTP headers:
GET /script.php?PARAM=VALUE&NEXTPARAM=VALUE HTTP/1.1
Accept: */*
Host: www.yoursite.com
or you send a POST request:
POST /script.php HTTP/1.1
Accept: */*
Host: www.yoursite.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
PARAM=VALUE&NEXTPARAM=VALUE
poolwin2001
March 12th, 2005, 02:58 AM
Now I would say, if you ask some question and two people answer it nearly the same way, than something is wrong with your question :)
Or that both of them have German or Sanskrit as their mother tongue.:)
Let me get this straight,you use GET method to pass on variables?or is it the POST or can both be used to pass on variables to a .php
khp
March 12th, 2005, 10:30 PM
Let me get this straight,you use GET method to pass on variables?or is it the POST or can both be used to pass on variables to a .php
Both post and get can be used to pass parameters to php. With get it's encoded into the URL, with Post it's stored in the http request header. The other and more important difference between post and get, is that the response to a get request may be cached by the browser or a web proxy, so the http server might not acctually recieve a get request every time someone views the page. Post requests on the other hand may not be cached.
bigBA
March 14th, 2005, 03:57 AM
Or that both of them have German or Sanskrit as their mother tongue.:)
Let me get this straight,you use GET method to pass on variables?or is it the POST or can both be used to pass on variables to a .php
and if you have had read the first response to your question, you should have noticed that you can use both methods...
wether its a matter of mother tongue or not... it is of iq. :p ;)
well, yes, the quotes were wrong, but we are here to show you the way, a little bit work from you is required also.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.