Passing Values ​​in the URL in PHP – A Simple Way to Pass Form Values

Passing values ​​in the URL in PHP is one of the easiest ways we can pass variables between web pages. The environment of the web is stateless, meaning that we can not just pass variable values ​​between web pages without adding some code to aid in the passing of values. Other more popular ways of preserving the state between web pages is by using sessions or cookies. But in this article, we're going to create a web form and see how we can pass values ​​from that form to another page.

Step One

Create a new file and name it form.php. This will be the form that will collect data from our user. The important thing to note here is the value for the action which is processform.php (we'll create this later). After you submit the form, the values ​​will be passed to processform.php.

Another thing to note is the value for the method which is GET. The GET method will show the values ​​being passed in the URL. You should also take note of the names for the input boxes which is firstname and phonenumber .

Customer Information

Customer Profile

Enter your firstname:

Enter your phone number:

Step Two

Create a new file and name it processform.php. This is going to be the form that will show us what values ​​the user entered in our form. You can also check the URL and see that the values ​​that the user entered in your previous form. You would not want to use the GET method when you have a form that is asking for a password. You have to use the POST method for that.

Customer Profile

Firstname:

Phone number:

Leave a Reply