Home >>PHP Tutorial >GET Method

GET Method

Form GET Method

GET method is unsecured method because it display all information on address bar/ url. By default method is get method. Using GET method limited data sends. GET method is faster way to send data.


In the given example user has to enter his/her name in text box, after entering the input he/she has to click on submit button to display the name entered by him/her. You can see the inputted value in address bar(url) also.

Create HTML Form Where user enter their name

<html>
	
<head>
		
<?php
			
echo $_GET['n'];		
		
?>
		
<title>get_browser</title></head>
	
<body bgcolor="sky color">
		
<form method="GET">
			
<table border="1" bgcolor="green">
				
<tr>
					
<td>Enter your name</td>
					
<td><input type="text" name="n"/></td>
				
</tr>
				
<tr>
					
					
<td colspan="2" align="center">
					
<input type="submit" value="show my name"/></td>
				
</tr>
				
			
</table>
		
</form>
	
</body>

</html>

In the given above example: user entered the name inside the text box , after entering the name he clicked on submit button and can see the output of the program means their name. User can check the input given by the user shows inside the URL because of get method.


Enter two number and print the sum of given numbers.

<html>
	
<head>
		
<title>get_browser</title>
			
<?php
		
error_reporting(1);
		
$x=$_GET['f'];
		
$y=$_GET['s'];
		
$z=$x+$y;
		
echo "Sum of two number = ".$z;
		
?>
	
</head>
	
<body bgcolor="sky color">
		
<form method="GET" >
			
<table border="1" bgcolor="green">
				
<tr>
					
<td>Enter your first number</td>
					
<td><input type="text" name="f"/></td>
				
</tr>
				
<tr>
					
<td>Enter your second number</td>
					
<td><input type="text" name="s"/></td>
				
</tr>
				
<tr align="center">			
					
<td colspan="2" >
					
<input type="submit" value="+"/></td>
				
</tr>
					
</table>
		
</form>
	
</body>

</html>

In the given above example: user has to enter the first number, second number after given the input click on "+" button, and check the output means the sum of two numbers. can also see the input given by him/her displays on address-bar(URL).


No Sidebar ads