This is a basic php getting started tutorial. we want to tell you how to use php functions to obtain form data. in php, three methods are provided to obtain data: post, get, and request, the most common method is $ _ POST and $ _ GET. check the $ _ REQUEST variable and PHP $ _ REQUEST.
This is a basic php getting started tutorial. we want to tell you how to use php functions to obtain form data. in php, three methods are provided to obtain data: post, get, and request, the most common method is $ _ POST and $ _ GET. check the $ _ REQUEST variable. The $ _ REQUEST variable in PHP contains $ _ GET, $ _ POST and $ _ COOKIE content.
The $ _ REQUEST variable of PHP can be used to obtain the results of form data sent through the GET and POST methods.
Instance 1:
-
-
- An HTML Form that callitself
-
-
-
-
- If (! Emptyempty ($ _ POST ['Guess ']) {
- Print "last guess:". $ _ POST ['Guess '];
- }
- ?>
-
-
-
-
Because the table provides a large amount of data, we try to use post to obtain it. more complex example 2:
Example 2:
-
-
- $ Self = $ _ SERVER ['php _ SELF '];
- $ Username = $ _ POST ['username'];
- $ Useraddr = $ _ POST ['useradd'];
- $ Comments = $ _ POST ['comments'];
- $ Sent = $ _ POST ['sent'];
-
- $ Form = "";
-
- If ($ sent)
- {
- $ Valid = true;
-
- If (! $ Username)
- {$ Errmsg. = "Enter your name... "; $ Valid = false ;}
-
- If (! $ Useraddr)
- {$ Errmsg. = "Enter your email address... "; $ Valid = false ;}
-
- If (! $ Comments)
- {$ Errmsg. = "Enter your comments... "; $ Valid = false ;}
-
- $ Useraddr = trim ($ useraddr );
- $ _ Name = "/^ [-! # $ % & '* +./0-9 =? A-Z ^ _ '{|} ~] + ";
- $ _ Host = "([-0-9A-Z] +.) + ";
- $ _ Tlds = "([0-9A-Z]) {2, 4} $/I ";
- If (! Preg_match ($ _ name. "@". $ _ host. $ _ tlds, $ useraddr ))
- {
- $ Errmsg. = "Email address has incorrect format! ";
- $ Valid = false;
- }
- }
-
- If ($ valid! = True)
- {
- Echo ($ errmsg. $ form );
- }
- Else
- {
- $ To = "php@h.com ";
-
- $ Re = "Feedback from $ username ";
-
- $ Msg = $ comments;
-
- $ Headers = "MIME-Version: 1.0rn ";
- $ Headers. = "Content-type: text/html ;";
- $ Headers. = "charset =" iso-8859-1 "rn ";
-
- $ Headers. = "From: $ useraddr rn ";
-
- If (mail ($ to, $ re, $ msg, $ headers ))
- {Echo ("Your comments have been sent-thanks $ username ");}
-
- }
- ?>
We can perform some processing on the data submitted by the user. we only talked about $ _ POST.
$ _ POST variable
The $ _ POST variable is an array with the variable name and value sent by the http post method.
The $ _ POST variable is used to collect the values in the form from method = "post" and send information from the form with the POST method, it is invisible to anyone (not displayed in the address bar of the browser), and there is no limit on the amount of sent information.