Getting user input by GET method in Php

Getting user input by GET method in Php
    In this article following thing should be studied:

  • What methods are used to gather informtion?
  • What is GET method?
  • How to use GET method.
  • Important NOTE.






There are two methods of getting user information that he provided in the form. And these methods are as follows:

  1. _GET
  2. _POST

In this Article you will be studying how to use the GET method for storing the values that user gives in the particular form.

GET method:

What is Get Method?

This is a method which we are using to collect information from the user's input in a form. This method is used for gathering strings, numeric values or any character. This method is not eligible for collecting any binary information and sending it to the server.

Binary information like images or any documents can't be accessed by this method. But still you can use this method if you are sending static data to the server.

How to use GET Method?

There are two things that should be in your mind while using this method.
  1. Set the method of form as "get".
  2. Use _GET[ ]  in the Php to store the form values in the variables.

Set method of form as GET:

Its a very easy code to be done in the HTML while initializing a form.

  • In body tag of html start the Form tag.
  • In this tag call the function method.
  • In this function give the method as "get".


#Source Code:

<!DOCTYPE HTML>
<html lang="en">
<body>
            <form method="get">
            </form>
</body>
</html>

Use of _GET[ ] in Php:

Its a case sensitive because in this step you are declaring variables and storing the input by user in these variables. You must have to mention that by what method you are gathering the information.

Check Condition:

  • First of all you have to put a check in php that if the user has clicked the submit button or not.
  • And in this check condition you have to declare the $_GET method.
  • This is to check if the user has pressed the button in the HTML Form.
  • In this condition further methods are done.





#Source Code:

<?php
      
      if (isset($_GET['Submit']))
       {
       }

?>

Storing Values:

  • Declare the variables in which data should be stored  (i.e $get_value).
  • Than store the values by giving input names (from html form input names) and do this by $_GET[ ] method.
  • Write the name of input in the Brackets in inverted comma.




#Source Code:

if (isset($_POST['Submit']))
{


$get_value1 = $_GET['input1'];
$get_value2 = $_GET['input2'];  
$get_value3 = $_GET['input3'];
$get_value4 = $_GET['input4'];


}

Input Names:

  • The form tags declared before is used for this.
  • In the form, create the table.
  • Now declare the table row.
  • In <tr> tag, start a tag <td> (table data).
  • An input method is used for showing an input bar to the user on Form.
  • Set it type as input, and name it for future use.





#Source Code:

<form method="get">
<table>
<tr>
<td><input type="text" name="input1" /></td>
<td><input type="text" name="input2" /></td>
<td><input type="text" name="input3" /></td>
<td><input type="text" name="input4" /></td>
</tr>
       <table>

</form>

NOTE:

The inputs user is providing should be shown as it is in the URL bar.

And to know how to insert these values in the DataBase Click the Following Link:

And to know how to insert these values in the Database Click the Link.

To create connection to database. Click the Link.


Related Post: