Pages

PHP $_POST

The PHP $_Post function is another way of grabbing the user inputted information.When a HTML form is used with its method="post" than the data of different elements of this form can be retreived by the PHP $_post function in the PHP page which is called on submission of the form.
The $_Post function gets the data with reference to the name attribute of the form elements e.g Textbox,Checkbox and Radio buttons.Unlike the $_GET function the PHP $_POST function makes the information transfer secure.The data is not visible to the user and it is not embedded in the URL and the amount of data to be shifted is almost unlimited too.
For more clear illustration let's go through to the following example...add the following code in a html file...




<HTML>
<HEAD>
<title>PHP $_POST demo</title>
</HEAD>
<BODY>
<h2><i>Who are you?</i></h2>
<FORM method="post" action="form1script.php">
<p>Name: <input type="text" name="_name" size=10></p>
<p>Nick: <input type="text" name="_nick" size=10></p>
<p><input type="submit" value="Enter"></p>
</FORM>
</BODY>
</HTML>

Now we have created our form and on submission this form will transfer its _name and _nick element's data to the form1script.php file.So we have to create a php file named form1script.php to do so,open notepad and type the following code and save it as form1script.php in the same directory in which your form html file exists.

<?php
$name = $_POST["_name"];
$nick = $_POST["_nick"];
echo "your name is ".$name ."and your nick is ".$nick;
?>
When the form sends information to the PHP page with its post method, the information becomes available to the $_POST function of PHP.which can be used for any purpose, here we are just echoing out this info.

 

1 comments:

  1. Code Mystery said,

    A good php tutorial,
    You can find some similar tutorial from https://www.codemystery.com/php-tutorials-for-beginners/

    on July 31, 2019 at 4:58 AM  


Post a Comment