Oj Obasi
Oj Obasi

I am also and will continue to be a student of web design and development. My tutorials may not be for you. If you feel that way, then search online for better tutorials.

PHP 5 Form $_Get method

Here we have an html form with two input fields, firstname and lastname.
We will be submitting our form to the same php file, so we will use the super global variable( $_SERVER["PHP_SELF"]) to return the file name of our page.

In this example we will us the 'method' 'get' and we will be collecting the form data using the $_GET superglobal.
$_GET is an array of variables passed to the current script through the URL parameters.

Your Html Form With Get as Method:

<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="200" border="1">
<td><label for="firstname">First Name</label></td>
<td><input type="text" name="firstname" id="firstname"></td>
<td><label for="lastname">Last Name</label></td>
<td><input type="text" name="lastname" id="lastname"></td>
<td><input type="submit" value="Submit Form!"></td>
Results of post form:<br>
Your first name is <?php echo $_GET["firstname"]; ?> <br>
And last name is <?php echo $_GET["lastname"]; ?> <br>

Your full name is <?php echo $_GET["firstname"]; ?> <?php echo $_GET["lastname"]; ?>

Lets say, you filled the form with the following information; firstname = Oj and last name = Obasi. When the form is submitted, you will get the following results:
Your first name is Oj
And last name is Obasi
Your full name is Oj Obasi.

URL of script before submitting form :
URL of script after submitting form :

Why use GET?

Get is used to send insensitve insensitive information like search engine keywords.
You should never use the Get Method to send sensitive information like passwords, credit card numbers.
With Get Method , the url can be bookmarked because the values are displayed in the url.
Get has a limit to the amount of information you can send :2000 characters.