Latest web development tutorials

PHP form

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

PHP form processing

One thing very important things to note when dealing with HTML form, PHP can come from HTML page form elementsautomatically become available to PHP scripts.


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

form.html file code is as follows:

<meta charset="utf-8">

<form action="welcome.php" method="post">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">


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

welcome.php files are as follows:

欢迎 <?php echo $_POST["fname"]; ?>!<br>
你的年龄是 <?php echo $_POST["age"]; ?>  岁。

Demo accessed through a browser as follows:

We will explain in PHP $ _GET and $ _POST variables in the next chapter.

Forms Authentication

Should whenever possible to validate user input (via client-side scripting). Browser validation is faster and can reduce the load on the server.

If the user needs to enter into the database, you should consider using server authentication. In the server authentication form a good way to pass the form of its own, instead of jumping to a different page. So that users can get an error message in the same form page. Users also easier to find mistakes.