Passing variable values from URL with PHP Get method

Today we look at how can we sent variable data from one page to another page through url. In real life web application we need to send data from one page to another page. 
To do this, we will open two pages. First page contains a URL with variable value and second page collects that value using PHP $_GET method. We name the first page is first_page.php and second page is second_page.php.  So the first page looks like this

<a href="second_page">Second Page</a>

Save this page in your localhost folder. This is a HTML URL example page. Now we see how to send data from url. To do this you need to put a question mark in the URL and then you need to write your variable with values. Now the page is

<a href="second_page?name=Sharif">Second Page</a>

In this portion we just set one value but in real life problem we need to send two or more values from url. To send two or more values you need to set & operator after each variable. So the page is
<a href="second_page?first_name=Sharif&last_name=Rahman">Second Page</a>

Now we catch the variable value from first page and we show it in the browser. Open the second_page.php file and write the following code.

<?php
echo $_GET['first_name'];
echo $_GET['last_name'];
?>
Save the code and try to understand the output. In this tutorial we use PHP $_GET method to catch the URL value. We have a great tutorial on PHP $_GET method.

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP