New Users learn how to use PHP programs to process web forms

Source: Internet
Author: User
Tags php form
PHP $ _ GET and $ _ POST variables are used to obtain information in the form, such as user input information. When processing HTML and PHP forms, PHP form operations must remember that any form element on the HTML page can be automatically used for PHP scripts: form example: htmlbodyformactionwelcome. phpme

PHP $ _ GET and $ _ POST variables are used to obtain information in the form, such as user input information. When processing HTML and PHP forms, PHP form operations must remember that any form element on the HTML page can be automatically used for PHP scripts: form example: html bodyform action = "welcome. php "me

PHP $ _ GET and $ _ POST variables are used to obtain information in the form, such as user input information.

PHP form operations

When processing HTML and PHP forms, we must remember that any form Element in the HTML page can be automatically used for PHP scripts:

Form example:

The preceding HTML page contains two input boxes [input field] And a [submit] button. When you fill in the information and click the submit button, the data in the form will be sent to the "welcome. php" file.

The "welcome. php" file is as follows:

Welcome .

You are Years old.

The above script will output the following result:

Welcome John.

You are 28 years old.

PHP $ _ GET and $ _ POST variables will be explained in the next chapter.

Form validity verification [Form Validation]

The information entered by the user should be verified through the client script program (such as JavaScript) browser as much as possible; the information validity verification through the browser can improve the efficiency and reduce the download pressure on the server.

If the information you enter needs to be stored in the database, you must consider verifying the validity on the server side. The best way to verify the information validity on the server is to send the form information to the current page for verification, rather than transfer it to other pages for verification. If an error occurs in the form, you can obtain the error information directly on the current page. This makes it easier for us to find error messages.

The PHP $ _ GET variable obtains the "value" from the form through the get method.

$ _ GET variable

The $ _ GET variable is an array containing the name [name] and value [value] (these names and values are sent through the http get method and can all be used ).

The $ _ GET variable uses "method = get" to obtain the form information. The information sent through the GET method is visible (it will be displayed in the address bar of the browser) and has a length limit (the total length of the information cannot exceed 100 characters [character]).

Case

After you click "Submit", the URL is displayed

"Welcome. the php file can use the "$ _ GET" variable to obtain form data (note: the name in the form field [form field] is automatically used as the ID keyword in the "$ _ GET" array ):

Welcome .
You are Years old!

Why use "$ _ GET "?

Note: If the variable value to be sent is too large, the http get method is not applicable. The number of sent messages cannot exceed 100 characters.

$ _ REQUEST variable

The PHP $ _ REQUEST variable contains $ _ GET, $ _ POST, and $ _ COOKIE content.

The PHP $ _ REQUEST variable can be used to obtain the form data sent through the "GET" and "POST" methods.

Case

Welcome .
You are Years old!

The function of the PHP $ _ POST variable is to get the form variable sent by the method = "post" method.

$ _ POST variable

The $ _ POST variable is an array containing the name [name] and the value [value] (these names and values are sent through the http post method and can all be used)

The $ _ POST variable uses "method = POST" to obtain the form information. The information sent through the POST method is invisible and there is no limit on the length of the information.

Case

After you click "Submit", the URL does not contain any form data.

"Welcome. the php file can use the "$ _ POST" variable to obtain form data (note: the name in the form field [form field] is automatically used as the ID keyword in the "$ _ POST" array ):

Welcome .

You are Years old!

Why use $ _ POST?

Variables sent through http post are not displayed in the URL.

There is no limit on the variable size.

$ _ REQUEST variable

The PHP $ _ REQUEST variable contains $ _ GET, $ _ POST, and $ _ COOKIE content.

The PHP $ _ REQUEST variable can be used to obtain the form data sent through the "GET" and "POST" methods.

Case

Welcome .

You are Years old!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.