PHP Forms Tutorial

The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.


PHP Form Handling

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.


The example below contains an HTML form with two input fields and a submit button:


<form action="welcome.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">


When a user fills out the form above and clicks on the submit button, the form data is sent to a PHP file, called "welcome.php":

"welcome.php" looks like this:


Welcome <?php echo $_POST[“fname”]; ?>!<br>
You are <?php echo $_POST[“age”]; ?> years old.


Output could be something like this:

Welcome John!
You are 28 years old.

The PHP $_GET and $_POST variables will be explained in the next lesson.

Both comments and pings are currently closed.

Comments are closed.

Designed for