In this tutorial, you will be learning about the $_POST[] variable.
$_POST[]
is what is known as a super global variable, meaning this is a variable that comes with PHP by default.
You will use $_POST
so often, it's impossible not to eventually understand it.
What Is $_POST?
$_POST[]
is used to collect form data sent to a page via the post method.
$_POST[]
is used more often than $_GET[]
due to its greater security.
Unless you have an overwhelmingly good reason to send data via get, you should send it via post.
Below is an example: first page (a.php) is a form with a method of post, while the second page (b.php) is the page that makes use of the form data using the $_POST
variable. We send a $_POST["a"]
variable value of aaa
and a $_POST["b"]
variable value of bbb
.
a.php
<html>
<head><title></title></head>
<body>
<form action="b.php" method="POST">
<input type="text" name="a">
<input type="text" name="b">
<input type="submit" value="submit">
</form>
</body>
</html>
Please keep in mind that you cannot use the $_POST variable to get data that was sent via the GET method. b.php
<?php
echo $_POST["a"];
echo $_POST["b"];
?>
Result