Home Backend Development PHP Tutorial PHP form form parameter passing details study_PHP tutorial

PHP form form parameter passing details study_PHP tutorial

Jul 21, 2016 pm 03:45 PM
form get php post Why Woolen cloth and deal with how have of Research surface form

Why? Because there are two types of form processing: GET and POST, it has always been a very confusing question how to pass the do parameters in both forms and obtain them in the same way in the background. Today, after several hours of experimentation, I finally I understand, so I’m posting this.
GET form:

Copy code The code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns ="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=gbk "/>
<title>The form uses the GET method to transfer values</title>
</head>
<body>
The value cannot be passed to action-get.php -->
<form action="action-get.php?parm=url-get" method="get">
<p> ;
                                                                                                                ​="hkey" value="hvalue" />
                                                                                                                                                                                           hidden" name="do" value="index" /> value="Submit"/>
                                                                                                                              PHP for GET form:



Copy code

The code is as follows:


<pre>
<?php
echo "The value of the parameter name is obtained through $_GET as ".$_GET["name"]." ,";
echo "The value of the parameter name is obtained through $_POST as ".$_POST["name"]. " ,";
echo "The value of parameter name is obtained through $_REQUEST as ".$_REQUEST["name"]." .rn"; echo "The value of parameter parm is obtained through $_GET as ".$ _GET["parm"]." ,"; echo "The value of parameter parm is obtained through $_POST as ".$_POST["parm"]." ,"; echo "The value of parameter parm is obtained through $ _REQUEST is obtained as ".$_REQUEST["parm"]." .rn"; echo "The value of parameter hkey is obtained through $_GET as ".$_GET["hkey"]." ,";
echo " "The value of parameter hkey is obtained through $_POST as ".$_POST["hkey"]." ,";
echo "The value of parameter hkey is obtained through $_REQUEST as ".$_REQUEST["hkey"]." . rn";
echo "The value of parameter do is obtained through $_GET as ".$_GET["do"]." ,";
echo "The value of parameter do is obtained through $_POST as ".$_POST[ "do"]." ,";
echo "The value of parameter do is obtained through $_REQUEST as ".$_REQUEST["do"]." .rn";
?>
</ pre>



Processing result output:

The value of parameter name is obtained as kj through $_GET, the value of parameter name is obtained as kj through $_POST, and the value of parameter name is obtained through $_REQUEST is obtained as kj.
The value of parameter parm is obtained through $_GET, the value of parameter parm is obtained through $_POST, and the value of parameter parm is obtained through $_REQUEST.
The value of parameter hkey is obtained through $_GET is hvalue, the value of parameter hkey is obtained through $_POST, and the value of parameter hkey is obtained through $_REQUEST as hvalue.
The value of parameter do is obtained as index through $_GET, and the value of parameter do is obtained through $_POST, parameter do The value is obtained as index through $_REQUEST.

POST form:


Copy code

The code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content- Type" content="text/html;charset=gbk"/>
<title>The form uses POST to pass values</title>
</head>
<body>
<!-- The parm and do parameters in action can be obtained through $_GET in action-post.php-->
<form action="action-post.php?parm=url- post&do=index" method="post">
                                                                                                                                      Value-->
                                                                                                                                                                                                                                                       >                                                                                             >



Copy code

The code is as follows:

<pre>
<?php echo "parameter The value of name is obtained through $_GET as ".$_GET["name"]." ,"; echo "The value of parameter name is obtained through $_POST as ".$_POST["name"]." ,";
echo "The value of the parameter name is obtained through $_REQUEST as ".$_REQUEST["name"]." .rn";
echo "The value of the parameter parm is obtained through $_GET as ".$_GET["parm "]." ,"; echo "The value of parameter parm is obtained through $_POST as ".$_POST["parm"]." ,"; echo "The value of parameter parm is obtained through $_REQUEST as" .$_REQUEST["parm"]." .rn"; echo "The value of parameter hkey is obtained through $_GET as ".$_GET["hkey"]." ,"; echo "The value of parameter hkey The value is obtained through $_POST as ".$_POST["hkey"]." ,";
echo "The value of parameter hkey is obtained through $_REQUEST as ".$_REQUEST["hkey"]." .rn";
echo "The value of the parameter do is obtained through $_GET as ".$_GET["do"]." ,";
echo "The value of the parameter do is obtained through $_POST as ".$_POST["do"] ." ,";
echo "The value of parameter do is obtained through $_REQUEST as ".$_REQUEST["do"]." .rn";
?>
</pre>



Processing result output:

The value of parameter name is obtained through $_GET, the value of parameter name is obtained as zkj through $_POST, and the value of parameter name is obtained through $_REQUEST. zkj.
The value of parameter parm is obtained as url-post through $_GET, the value of parameter parm is obtained as url-post through $_POST, and the value of parameter parm is obtained as url-post through $_REQUEST.
The value of parameter hkey is obtained through $ _GET is obtained as, the value of parameter hkey is obtained as hvalue through $_POST, and the value of parameter hkey is obtained as hvalue through $_REQUEST.
The value of parameter do is obtained as index through $_GET, and the value of parameter do is obtained through $_POST as, The value of the parameter do is obtained as index through $_REQUEST.
Conclusion:
The GET form value can be obtained through _GET; but the parameters set through the url parameter of the action cannot always be obtained
The POST form value can be obtained Obtained through _POST; but the parameters set through the url parameter of the action can be obtained through _GET
The same variables can be obtained through _GET, but they are set through hidden variables in the GET form, and through action in the POST form. url parameter settings
http://www.bkjia.com/PHPjc/320280.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/320280.html

TechArticle

Why? Because there are two types of form processing: GET and POST, it has been very confusing how to pass the do parameters in both forms and obtain them in the same way in the background...

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How to fine-tune deepseek locally How to fine-tune deepseek locally Feb 19, 2025 pm 05:21 PM

How to fine-tune deepseek locally

deepseek why can't you log in deepseek login portal deepseek why can't you log in deepseek login portal Feb 19, 2025 pm 05:00 PM

deepseek why can't you log in deepseek login portal

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

Why can't the Bybit exchange link be directly downloaded and installed? Why can't the Bybit exchange link be directly downloaded and installed? Feb 21, 2025 pm 10:57 PM

Why can't the Bybit exchange link be directly downloaded and installed?

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

PHP Program to Count Vowels in a String

Free market software app website Free market software app website Mar 05, 2025 pm 09:03 PM

Free market software app website

See all articles