3/22/15

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.

Enter your name and click on submit button.

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 to display the name entered by him/her.
Eg i
<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 colspon="2" align="center">
     <input type="submit" value="show my name"/></td>
    </tr>
    
   </table>
  </form>
 </body>
</html>
Output abhishek
Enter your name  
In the given above example:
user entered the name inside the text box “Abhishek”, after entering the name he clicked on submit button
and can see the output of the program means Abhishek.
user can check the input given by the user shows inside the url because get method.

Enter two number and print the sum of given numbers.

Eg ii
<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 colspon="2" >
     <input type="submit" value="+"/></td>
    </tr>
    
   </table>
  </form>
 </body>
</html>

Output :  Sum of two number = 500
Enter your first number
Enter your second number
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 addressbar(url).
Eg iii
 <?php
  error_reporting(1);
  $id=$_GET['id'];
  $pass=$_GET['pass'];
  if(isset($_GET['signin']))
  {
   if($id=="Deep" && $pass=="Deep123")
   {
   header('location:http://truetech4.blogspot.in/');
   }
   else
   {
  echo "<font color='red'>Invalid id or password</font>";
   }
  }
 ?>
 
 <body>
 <form method="get">
  <table border="1" align="center">
   <tr>
    <td>Enter Your Id</td>
    <td><input type="text" name="id"/>
    </td>
   </tr>
   <tr>
    <td>Enter Your Password</td>
    <td><input type="password" name="pass"/>
    </td>
   </tr>
   <tr>
    <td><input type="submit" name="signin" value="SignIn"/>
    </td>
   </tr>
  </table">
  </form>
 </body>
 
 Output : Redirect on truetech4.blogspot.in (check url)
 Enter your id       
 Enter your password 
   
In the given above example:
user has to enter the username and the password,
after entering the valid username and password click on “SignIn” button, if the user is valid the header() function redirects on next page “http://truetech4.blogspot.in/” otherwise show an error message Invalid id or password

0 comments:

Post a Comment

SUBSCRIBE TO NEWSLETTER

FIND US ON FACEBOOK

FIND US ON Twitter

FIND US ON GOOGLE+