This tutorial explains how to handle submitted form data in one file with PHP and also how to work with the request method in PHP.
The request method can be checked to see if data has been submitted using the GET or POST method. For example, if the POST method was used, then a PHP program can then collect data using the POST method.
Watch the video below and then scroll down to see the sample code.
Sample PHP code:
<?php if($_SERVER['REQUEST_METHOD'] !='POST'){ echo' <form action="" method="POST"> <p>Enter your name:</p> <p>Name: <input type="text" name="name"></p> <p><input type="submit"></p> </form> '; } else{ if(!empty($_POST['name'])){ $name = $_POST['name']; echo "Hello, $name"; } else{ $name = NULL; echo "You must enter a name."; } } ?>