PHP GET POST Form Methods – PHP Tutorial

Today we are going to learn about PHP GET POST form submit methods. When we submit some form in PHP then we need to retrieve those input or submitted data in another page or in the same page with GET & POST methods. With this PHP GET POST methods form data can be submitted. Both methods working for the same purpose but difference between PHP post and PHP get methods listed later in this post. Basically PHP form submit and after submit we need to access those submitted data for some further work like insert into database, login check, registration, fill contact form etc. Now we are going to learn and understand each step of PHP get post with example. First we need a form and for form submit in PHP we need to write two form attribute which are form action and form method in the following way.

Take a quick look at php get post method live demo to understand php form methods get & post. Also you can free download this php form methods example script from here and can try in your localhost or live server where you want to do.

Example of php submit form with get method

<form action="action.php" method="get">
//form input field for filling data goes here
</form>

In below example we mentioned that this PHP form submit with get method. Similarly we can use PHP POST method instead of PHP GET method.

Difference between GET & POST method:

PHP get method

:

  1. GET requests can be cached and shown in URL as a parameter.
  2. GET requests remain in the browser history.
  3. GET requests can be bookmarked.
  4. GET requests should never be used when dealing with sensitive data.
  5. GET requests have length restrictions.
  6. GET requests should be used only to retrieve data.
  7. Get method not secure for any confidential data.
PHP post method

:

  1. POST requests are never cached and not display in url.
  2. POST requests do not remain in the browser history
  3. POST requests cannot be bookmarked
  4. POST requests have no restrictions on data length
  5. POST method more secure.

Learn PHP GET POST form submit methods

GET method

As explained earlier, in php get method after form submit , it converts data into a query string in URL known as Url Encoding and you can easily get shown all the value in URL. Which contains both page link and encoded information separated by the ? character.

http://click4knowledge.com/index.php?name=click4knowledge&email=info@click4knowledge.com

Here http://click4knowledge.com/index.php this is the action page and after ? all the part are contain submitted data.

PHP Form with get method : Below code is an HTML form with method=”get” for user to fill information.

<form action="" method="get">
<input type="text" name="name" placeholder="Your Name" />
<input type="text" name="email" placeholder="Your Email" />
<input type="submit" name="submit" value="Submit">
</form>

Action page retrieve submitted data with get method: Below code has PHP script with PHP $_GET variable is used to receive sent information at server side.

<?php
if( $_GET["name"] || $_GET["email"])
{
echo "Name: ". $_GET['name']. "<br />";
echo "Email: ". $_GET["email"]. "<br />";
}
?>

All the submitted data by Get method can be readable in address bar so, never use Get method for sending sensitive information.

POST method

PHP Form with post method :For PHP post method we are use method=”post” and after form submit we retrieve the submitted value with PHP $_POST variable.

<form action="" method="post">
<input type="text" name="name" placeholder="Your Name" />
<input type="text" name="email" placeholder="Your Email" />
<input type="submit" name="submit" value="Submit">
</form>

Action page retrieve submitted data with post method: Below code has PHP script where, $_POST array variable is used to receive submitted information at server side after form submit in post method.

<?php
if( $_POST["name"] || $_POST["email"])
{
echo "Name: ". $_POST['name']. "<br />";
echo "Email: ". $_POST["email"]. "<br />";
}
?>

Query string or submitted data string , generated by Post method never appears in address bar i.e. it is hidden for the user so, we can use this method for sending sensitive information to server. Moreover, we can make use of this method to send data to the server without any restrictions to data size.

In our example, we allow user to choose a method via select box and by default GET method open.

In this way we can use PHP forms with get and post method. $_GET and $_post is use to retrieve the input value. So basically if your query about get post method,post PHP , get PHP, PHP $_get, PHP $_POST form methods, get & post, PHP post method, PHP get method i think this PHP tutorial example will be very helpful for you. So, don’t miss to learn and practice yourself. Thanks for watching this tutorial about php get post method. You can try yourself and share with your friends. I will share some useful script in PHP as well as some tips and tricks in PHP programming. Viewers can subscribe our newsletter to get all the updates about web programming. Share and likes will be appreciated also help to evaluate our self.

Support
If you need any help regarding the same please feel free to comment we love to help you.

2 responses to “PHP GET POST Form Methods – PHP Tutorial”

  1. Lawren says:

    Magnificent publish, very informative. I’m wondering why the other specialists of this sector do not realize this. You should proceed your writing. I am confident, you have a great readers’ base already!

  2. chiave says:

    Valuable info. Fortunate me I discovered your website by accident, and I am stunned why this coincidence did not happened earlier! I bookmarked it.

Leave a Reply

Your email address will not be published. Required fields are marked *