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

PHP Form Handling

This document discusses PHP form handling. It explains that forms allow users to input data into fields that are then sent to a web server. There are two main methods for sending this data - GET and POST. GET puts the data into the URL string, while POST embeds it in the HTTP request body. Both create arrays of key-value pairs that PHP can access through the $_GET and $_POST superglobals. The document provides an example using a simple form to collect a name and age, then outputs it using the $_POST array in a PHP file.

Uploaded by

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

PHP Form Handling

This document discusses PHP form handling. It explains that forms allow users to input data into fields that are then sent to a web server. There are two main methods for sending this data - GET and POST. GET puts the data into the URL string, while POST embeds it in the HTTP request body. Both create arrays of key-value pairs that PHP can access through the $_GET and $_POST superglobals. The document provides an example using a simple form to collect a name and age, then outputs it using the $_POST array in a PHP file.

Uploaded by

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

PHP form handling

Form
• A Document that containing blank fields, that
the user can fill the data or user can select the
data.
• It is like interface to send data to web server
• There are two ways the browser client can
send information to the web server.
The GET Method
The POST Method
GET and POST
• Both GET and POST create an array
e.g. array( key1 => value1, key2 => value2,
key3 => value3, ...)
• This array holds key/value pairs, where keys
are the names of the form controls and values
are the input data from the user.
• The respective arrays are
$_GET and $_POST (built in arrays)
The GET Method
• Information sent from a form with the GET
method is visible to everyone (all variable
names and values are displayed in the URL).
• GET also has limits on the amount of
information to send. The limitation is about
2000 characters.
• GET may be used for sending non-sensitive data.
• Note: GET should NEVER be used for sending
passwords or other sensitive information!
The POST Method

• Information sent from a form with the POST method


is invisible to others (all names/values are
embedded within the body of the HTTP request)
• Has no limits on the amount of information to send.
• However, because the variables are not displayed in
the URL, it is not possible to bookmark the page.
• Developers prefer POST for sending form data.
Example (read and display form data)
• A form (name and age data)
<html>
<body>
<form action =“welcome.php” method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>

</body>
</html>
PHP code (welcome.php)
<html>
<body>
<?php
$a=$_POST['name'];
$b=$_POST[‘age'];
echo "Welcome ".$a"<br />";
echo "You are ". $b. " years old.";
?>
</body>
</html>

You might also like