This article mainly introduces the introduction of PHP form 2 methods and simple examples, very practical, the need for small partners can refer to.
Handling GET Requests
The implementation of the function is to enter the name after the page display "Hello XXX"
To create an HTML file hello.html:
?
1 2 3 4 5 6 7 8 9 10 11 12-13 |
<! DOCTYPE html> |
Create PHP file hello.php:
?
1 2 3 4 5 6 7 8 9 10 11 12-13 |
<?php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/30 * time:15:03/Header ("content-type:text/html; Charset=utf-8 "); if (isset ($_get[' name ')) &&$_get[' name '] {//If there is a value and is not empty echo ' Hello '. $_get[' name ';} else{echo ' please input name ';} |
The GET request places the form's data explicitly in the URI and limits the length and data value encoding, such as: Http://127.0.0.1/hello.php?name=Vito
Process POST Requests
Implementation of a simple addition operation function
To create an HTML file add.html:
?
1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15 |
<! DOCTYPE html> |
Create PHP file add.php:
?
1 2 3 4 5 6 7 8 9 10 11 12 13-14 |
<?php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/30 * time:18:02/if ($_post[' num1 ']&&$_post[' num2 ']) {echo $_post[' NUM1 ']+$_post[' num2 ']; }else{echo ' please input num ';} |
Post requests place form data in the HTTP request body with no length limit
Form action= "" means: Form is the forms, action is to address, that form form needs to be submitted to where
The above mentioned is the entire content of this article, I hope you can enjoy.