php-general Digest 12 Feb 2011 19:57:06 -0000 Issue 7178
Topics (messages 311253 through 311255):
using BOTH GET and POST in the same page.
311253 by: Ashim Kapoor
311254 by: Jim Lucas
311255 by: Nathan Rixham
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Dear All,
I am reading "PHP5 and MySQL Bible". Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas? It is not clear to me as to how to implement
this.
Many thanks,
Ashim.
--- End Message ---
--- Begin Message ---
On 2/11/2011 9:23 PM, Ashim Kapoor wrote:
Dear All,
I am reading "PHP5 and MySQL Bible". Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas? It is not clear to me as to how to implement
this.
Many thanks,
Ashim.
But basically, the short of it is this.
<form action="/process.php?page_id=22&action=AddUser" method="POST">
<input type="hidden" name="action" value="DelUser" />
<table width="100%">
<tbody>
<tr>
<td align="right" width="40%">
Name:</td>
<td width="60%">
<input name="FullName" type="text" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Submit Form" />
<input type="reset" value="Reset Form" /></td>
</tr>
</tbody>
</table>
</form>
When submitted with data to this:
<?php
# filename:process.php
print_r($_GET);
print_r($_POST);
print_r($_REQUEST);
?>
Will result in this:
Array
(
[page_id] => 22
[action] => AddUser
)
Array
(
[action] => DelUser
[FullName] => Jim Lucas
)
Array
(
[page_id] => 22
[action] => DelUser
[FullName] => Jim Lucas
)
Check out the example that I wrote here http://www.cmsws.com/?page_id=5
Jim Lucas
--- End Message ---
--- Begin Message ---
Ashim Kapoor wrote:
Dear All,
I am reading "PHP5 and MySQL Bible". Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas? It is not clear to me as to how to implement
this.
I noticed you've already received one response, so here's some more
background info.
It's using $_GET and $_POST in the same script, not HTTP GET and HTTP
POST. $_GET in PHP correlates to the query string parameters in the URL
requested, $_POST in PHP correlates to form data which is POSTed to the
server inside a message, with the type application/x-www-form-urlencoded.
One could say that $_GET and $_POST are named misleadingly, and that
infact what you have is $_PARSED_QUERY_STRING_FROM_URL and
$_POST_DATA_MAYBE .
The two are quite separate and can both be used at the same time.
HTML forms allow a method to be set, GET or POST, if GET then the form
is treated like an URL construction template, if POST then it's treated
like a message body construction template.
It's worth reading up on both HTTP and HTML Forms when using PHP, since
PHP is a "Pre Hypertext Processor" and HTTP is the Hypertext transfer
protocol, and HTML is the Hypertext markup language :)
Best,
Nathan
--- End Message ---