i

PHP Tutorial

PHP Form Handling

When we create dynamic websites, it allow us to store, retrieve, update and delete the data and using forms we can collect the data user fills or user can select the data using forms. In PHP,  forms are handled using $_GET and $_POST method. These methods are used to collect the data from user inputs.

Let us see how we can retrieve and send the data with the below example.

First we need to create a form using HTML as below.

  • $_GET method creates an array of variables that are passed to the script using URL parameters whereas $_POST method creates an array of variables that are passed to the script using HTTP POST method.

  • Both $_GET and $_POST are super global variables and are always accessible anywhere in the php script.

  • Information that is sent using $_GET method is visible to all and displayed in the URL whereas information sent using $_POST method is invisible to everyone.

  • GET method can be used to send non-sensitive data like hobbies, interests etc. whereas POST method can be used to send personal details like password, login Id etc.