PHP forms and user input

The $_GET and $_POST variables in PHP are used to retrieve information in a form, such as user input.

Before studying this chapter, you can review the HTML form first

A form is an area containing form elements.

Form elements allow users to enter content in the form, such as text areas, drop-down lists, radio-buttons, checkboxes, etc.

The form uses the form tag

to set the

Specific review URL: HTML form

PHP form processing

There is one very important thing worth mentioning Note that when processing HTML forms, PHP can automatically make form elements from the HTML page available to PHP scripts.

Example

The following example contains an HTML form with two input boxes and a submit button.

form.html file code is as follows:

   php中文网(php.cn) 
名字: 年龄:

When the user fills out the above form and clicks the submit button, the form data will be sent to the PHP file named "welcome.php" :

welcome.php file is as follows:

Your age is years.

The demonstration of accessing through the browser is as follows:

101.gif


#We will explain $_GET in PHP in the following chapters and the $_POST variable.

Form Validation

User input should be validated (via client script) whenever possible. Browser validation is faster and reduces the load on the server.

If user input needs to be inserted into the database, you should consider using server validation. A good way to validate a form on the server is to pass the form to itself, rather than jumping to a different page. This way users can get error messages on the same form page. It will be easier for users to find errors.

Continuing Learning
||
php中文网(php.cn)
名字: 年龄:
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!