PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>Beginners> PHP Forms and User Input

PHP Forms and User Input

FROM: AUTHOR: TIME:2008-03-29 HITS:

The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. phpsu is a phpschool


PHP Form Handling

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

phpsu

Form example: welcome to phpsu.com

<html>
<body> welcome to phpsu.com
<form action="welcome.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form> do you kown phpsu.com?
</body>
</html> phpsu is a phpschool

The example HTML page above contains two input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the "welcome.php" file.

phpsu is a phpschool

The "welcome.php" file looks like this:

www.phpsu.com

<html>
<body> do you kown phpsu.com?
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.

do you kown phpsu.com?

</body>
</html> phpsu

A sample output of the above script may be:

phpsu is a phpschool

Welcome John.
You are 28 years old.

phpsu.com

The PHP $_GET and $_POST variables will be explained in the next chapters. phpsu.com


Form Validation

User input should be validated whenever possible. Client side validation is faster, and will reduce server load.

phpsu

However, any site that gets enough traffic to worry about server resources, may also need to worry about site security. You should always use server side validation if the form accesses a database. phpsu.com is a free phpscool

A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error. http://www.phpsu.com


TITLE:PHP Forms and User Input
Previous:PHP Functions
Next:PHP $_GET
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:44:59 GMT-8 2008