Home >Backend Development >PHP Tutorial >PHP $_POST
PHP $_POST
PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also commonly used to pass variables.
The example below shows a form with input fields and a submit button. When the user clicks the submit button to submit the data, the form data is sent to the file specified in the action attribute of the ff9c23ada1bcecdd1a0fb5d5a0f18437 tag. In this example, we specify the file itself to handle the form data. If you wish to use another PHP page to handle the form data, change the file name to a file name of your choice. We can then use the superglobal variable $_POST to collect the value of the input field:
Instance
<html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php $name = $_POST['fname']; echo $name; ?> </body> </html>