PHP form read form data transfer
The subject of PHP Form should be divided into two parts. The first part is the part of HTML Form form design, and the second part is to use PHP to obtain the information passed by the form, because HTML Form itself is only a simple form, which is static. For the page, you need to let the netizen fill in the information. When the netizen presses the button to send the form ( HTML button ), the form will send the information. At this time, you must use PHP's $_POST or $_GET variable to receive the information. This article is about To introduce the process and examples of this PHP receiving Form.
PHP form read form data transfer example
As mentioned in the first paragraph, completing a form data transfer can be divided into two parts, of course, it can also be completed with only one file, but we hope to use a more basic one The way to introduce, that is, prepare the HTML Form page (named PHP_Form.html) for filling in information for netizens, and the PHP file (PHP_Form.php) for reading the form data for the server. You can use these two files to complete Presents the process of transferring data in a PHP Form.
HTML Form: PHP_Form.html
Text input field: <input type="test" name="YourName">
<input type="submit" value="submit form">
</form >
Text input field:
In order to simplify the example, in this code, only a simple text input field ( input text ) and a button to send the form are prepared. The form itself will use POST to pass the data to the program PHP_Form.php. GET can also be used here, but PHP $_GET must also be used to receive in PHP_Form.php. The basic rule is that POST or GET can be used in HTML From, but it must correspond correctly to PHP Script. This part You can refer to: The usage difference between GET and POST in HTML form .
PHP receives the Form file: PHP_Form.php
$YourName=$_POST[YourName];
echo'The received content is:'.$YourName;
?>
The function of this PHP file is quite simple. The first line uses the variable $YourName to store the received data, and the right side of the equal sign uses the PHP built-in $_POST variable to correspond to the post transfer method of the PHP_Form.html form, inside the parentheses YourName corresponds to the name of the text input field in PHP_Form.html. It should be noted here that $_POST is not equal to $_post, and capitalization is completely different. According to the rules of PHP, if it is written in lowercase, it will be invalid. Please refer to: PHP POST usage and examples .
The above two simple programs should be able to see the complete process of PHP obtaining Form data. Of course, HTML Form has many input fields. Each input field has different functions, including input text , textarea , select option , and Checkboxes. , Radio Buttons ..., etc., can transmit and receive data in this way. The PHP Form technique can be said to be an introductory basis for PHP programming.
 
 
Post a Comment
0 Comments