0% found this document useful (0 votes)
7 views

PHP Presentation 3 (PHP Forms)

PHP Presentation 3 (PHP Forms) LECTURE

Uploaded by

reekee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

PHP Presentation 3 (PHP Forms)

PHP Presentation 3 (PHP Forms) LECTURE

Uploaded by

reekee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PHP FORM HANDLING

PHP Forms

• A very powerful feature of PHP is the way it handles HTML


forms!

• 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.
Example:

HTML FORM

<html>
<body>
<form action="welcome.php" method="POST">
Enter your name: <input type="text" name="name" >
Enter your age: <input type="text" name="age" >
<input type="submit" >
</form>
</body>
</html>
PHP Script

The "welcome.php" file looks like this:

<html>
<body>
Welcome <?php echo $_POST[‘name’]; ?>.<br >
You are <?php echo $_POST[‘age’]; ?> years old!
</body>
</html>
Here is how it works:

The $_POST[‘name’] and $_POST[‘age’] variables are


automatically set for you by PHP. The $_POST contains all
POST data.

Note: If the method attribute of the form is GET, then the form
information will be set in $_GET instead of $_POST.

* $_POST Method – the browser sends the data in two steps:


the browser first contacts the form-processing server specified
in the action attribute, and, once the contact is made, sends
the data to the server in a separate transmission.

* $_GET Method – it contacts the form-processing server


and sends the form data in a single transmission step: the
browser appends the data to the form’s action URL,
separated by the question mark (?) character.
OUTPUT OF EXAMPLE 1

HTML (“sample1.html”)
OUTPUT OF EXAMPLE 1

PHP (“welcome.php”)
Example 2

ORDER.HTML
Example 2

ORDER.PHP
OUTPUT OF EXAMPLE 2:

HTML (“order.html”)
OUTPUT OF EXAMPLE 2:

PHP (“order.php”)

You might also like