Pass information using GET method (Querystring)

It is possible to pass variables through URL. When you are using GET method in the FORM element the information will be send to the destination file through URL using the concept of Query String.
A Query String is a collection of Name-Value pairs separated by & sign. Every Query String starts with ? in the URL. Consider Following URL:
Pass Data Using URL While you are passing variables through a URL using query string you have to face following difficulties:
(1) The information you are trying to pass to the destination file is visible in the URL. So it is insecure and every one can view the information send by you. Thus it is not suitable for transferring secure information.
(2) You can transfer limited amount of information using this method because the information is transferred via URL.


Step 1: Create QueryString1.Php file as shown below:

<title>QueryString Demo</title>
<form name="Form1" method="GET" action="QueryString2.php">
Enter Your Name:<br>
<input type="Text" name="Name" ><br>
Enter Your City:<br>
<input type="Text" name="City" ><br>
<input type="submit" name="submit" value="Submit">

Step 2: Create QueryString2.php file as shown below:

$Name = $_GET['Name'];
$City = $_GET['City'];
echo "Your Name is ".$Name. "<br/>";
echo "You Live In ".$City. "<br/>";

In above script we use $_GET [‘Variable Name’] function which allows you to retrieve value of the variables from URL.
Step 3: Now run the QueryString1.php file

Pass Data Using URL

After entering Name and City in the textbox when you click on submit button, it will transfer name and city through Query String in the URL as shown below:

Pass Data Using URL

Download Projects

Download Programs