How to recevethe data sent from a form in php by using php form variable get , post or request method?

php form variable

php form variable

 

To generate business online and to get connected with business and website user form submission is the ultimate way. But form after submission of the form have to receive the data and use them also, so in this post we are going to learn how to receive the data sent from a form in php by using php form variable get , post or request method.

How to submit a form, from html to php?

To submit a html form there must have action which will submit the form in a targeted page, a method which indicts the submission method of the form and also a ency type. There should be some field inside the form and also a submit button to make the submit event.

A sample html form is given below:

<html>
<body>

<form action=”welcome_post.php” method=”post”>
Name: <input type=”text” name=”name”>
Contact No: <input type=”text” name=”contact_no”>
<input type=”submit”>
</form>

</body>
</html>

 

in case if want to send the value through get method then have to change the method of form to get and then the code of the form will be as described below,

<html>
<body>

<form action=”welcome_post.php” method=”post”>
Name: <input type=”text” name=”name”>
Contact No: <input type=”text” name=”contact_no”>
<input type=”submit”>
</form>

</body>
</html>

 

How to get the value submitted through get method in php?

First need to know what is get method, while a form is submitted in a get method the values are sent through the url, so using browser history the anyone can be find the value so the values sent from get method are less secure. Also all browser can sent a limited amount of data through url so less amount of data can be sent through the get method.

now to get the value in php sent through get method is, $_GET thus all the get value can be fetched as an array of GET variable, so to get a particular value have to pass the input fields name as a get method array key.

An example of php get method is given below:

<?php
echo ‘Name= ‘ . $_GET[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_GET[“contact_no”];
?>

 

How to get the value submitted through post method in php?

After a form submission unlike get method the value are not sent through the url so no one can be able to get the values submitted by post method, The amount of data is limited by the server only so a vast amount of data can be sent through the post method like image or video etc.

now to receive the value in php sent through post method is, $_POST thus all the post value can be fetched as an array of POST variable, so to get a particular value have to pass the input fields name as a POST method array key.

An example of PHP POST method is given below:

<?php
echo ‘Name= ‘ . $_POST[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_POST[“contact_no”];
?>

 

Different between GET and POST method,

Both GET and POST create an array. The array holds key/value, where keys are the names of the form input fields and values are the data given as input in the form fields by the user.

Both GET and POST are treated as $_GET and $_POST. These are super global, That is they are accessible inside or outside of scope or functions.

$_GET is an array of variables passed through the URL which is visible to all user.

$_POST is an array of variables passed through the HTTP POST method which is not visible by all user.

And also it can be said that through get method we can send less amount of data where through post method we can send greater amount of data.

The amount of data sent through get method is dependable on browser and php both as php have its data limit and browser have its url length limit. but the data sent through post method is depend on the php only that how much data limit is there.

PHP Form Variable $_REQUEST

Using $_REQUEST in php can be received array data sent through get or post method from a html form.

an example of $_REQUEST is given below:

<?php
echo ‘Name= ‘ . $_REQUEST[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_REQUEST[“contact_no”];
?>

 

PHP Form Variable $_REQUEST, $_POST and $_GET

All the three php form variable $_REQUEST, $_POST and $_GET are super global and array type variable. that is it can be receive data from inside or outside of scope or function.

In this post we have gone through how to receive the data sent from a form in php by using php form variable get , post or request method. I hope that you are able to get a clear idea on the php form variable.

Thanks for reading.

Share The Post On -

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.