Reading Data in Web Pages:
• A very common application of PHP is to have an HTML form gather information from
a website's visitor and then use PHP to do process that information.
• The PHP $_GET and $_POST variables are used to retrieve information from forms,
like user input.
• 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
• The example below contains an HTML form with two text input fields and a submit
• Text fields are one line areas that allow the user to input text.
• The name setting adds an internal name to the field so the program that handles the
form can identify the fields.
The value setting defines what will appear in the box as the default value.
• When a visitor clicks a submit button, the form is sent to the address specified in the
action setting of the <form> tag.
• The name setting adds an internal name to the button so the program that handles
the form doesn't confuse the button with the other fields.
• The value setting defines what is written on the button.
• When a user fills out the form above and click on the submit button, the form data is
sent to a PHP file, called “inputField.php":
" inputField.php" looks like this:
• Be sure to take notice the names of the form data names, as they represent the keys
in the "$_POST" associative array.
• Next the output could be something like this:
• The built-in $_POST function is used to collect values from a form sent with
• Information sent from a form with the POST method is invisible to others and has no
limits on the amount of information to send.
• When to use method="get"?
• When using method="get" in HTML forms, all variable names and values are
displayed in the URL.
Note: Because of the above behavior this method should not be used when sending
passwords or other sensitive information!
• However, because the variables are displayed in the URL, it is possible to bookmark
the page. This can be useful in some cases.
Note: The get method is not suitable for large variable values; the value cannot
exceed 100 characters.