May 11, 2021 PHP
The $and $_GET in PHP _POST are used to retrieve information in the form, such as user input.
It is important to note that when working with HTML forms, PHP automatically turns form elements from HTML pages into available to PHP scripts.
The following example contains an HTML form with two input boxes and a submit button:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
When the user completes the form above and clicks the submit button, the form's data is sent to a PHP file .php "welcome":
The "welcome.php" file looks like this:
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br>
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
The output looks like this:
We'll cover the $and $_GET variables in PHP _POST chapter.
User input should be validated (via client scripts) wherever possible. Browser authentication is faster and can reduce the load on the server.
If user input needs to be inserted into the database, you should consider using server authentication. A good way to validate a form on the server is to pass it on to itself, rather than jumping to a different page. T his allows the user to get an error message on the same form page. Users are also more likely to find errors.
In the next section, you'll learn more about PHP form validation.