JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKAS

JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKASI
POLITEKNIK SEBERANG PERAI
PSP

MODULE CODE : FP 512
LAB
:
7
TITLE : PHP and WEB FORM

MODULE : Web Programming 1
DATE :

Objective : 1. Creating Simple Input Form
2. Handling Input From Form With PHP
3. Combining HTML and PHP In Same Page
Equipment : 1. Computer with Windows OS
2. Internet
Task1 : Creating Simple Input Form
HTML FORM and input elements add interactivity to the web site. The HTML forms handle very
important operations at the website that is getting the input from user. All the input elements should be

enclosed within the opening and closing tag :

The input elements

Two important attribute for FORM tag is ACTION and METHOD. The ACTION attribute specifies the
page which handles the input from the user. Usually, this will be a script which processes the data
supplied by user (ex.: displaying in other page, storing in database etc).
The METHOD attribute is either POST or GET that is the way data passed to the page which handles
the input mentioned in ACTION. If POST method is used, the information is sent to the server as part of
the data body and will not be visible in the URL box in the user’s browser. If GET method is used, the
input values are passed as part of the URL. If we don’t specify the method, GET is taken as default.

The input elements


1. Write the HTML code as follows, save as borang.html and display the output.

Simple Form



Text :
Password :

JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKASI
POLITEKNIK SEBERANG PERAI
PSP

Textarea :


Selection List :

Penang
Kedah
Johor

Radio button :
Male
Female
Check box :

PHP
JSP
ASP
Submit :
Reset :



(Note : Review all eight form elements introduced in the HTML document above. Note that for Text,
Password and Textarea, input are entered by user, meanwhile for Selection List, Radio Button and
Check Box, input are assigned by the programmer using the value attribute.)

Task 2 : Handling Input From Form With PHP
Please keep in mind that HTML part of the forms does not have any feature in processing the data
submitted. You should use server-side scripting language such as PHP to handle the data submitted by
the forms.
The PHP $_POST or $_GET variable are used in collecting the data from form. If the data is sent using
POST method, $_POST variable is used, meanwhile if the data is sent using GET method, $_GET
variable is used. $_REQUEST variable can be used to get the data sent with both GET and POST
methods.


JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKASI
POLITEKNIK SEBERANG PERAI
PSP

1. Write the PHP script as follows and save as proses.php.


”.$element1;
”.$element2;
”.$element3;
”.$element4;
”.$element5;
”.$element6;

2. Open the borang.html file in the test server. Fill in the form and submit. Is the value entered
displayed in proses.php file ?
Task 3 : Combining HTML and PHP In Same Page
In some circumstances we might want to include PHP script in the same page as a hard-coded HTML
form. Such a combination can be useful if we need to present the same form to the user more than

once. To achieve this, just point the ACTION attribute in the FORM tag to $_SERVER[PHP_SELF].
1. Write the script as follows and save as borang.php.

Simple Form 2



JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKASI
POLITEKNIK SEBERANG PERAI
PSP

2. Run and test the script. Is it works ?

Questions :
1. Explain the difference between $_POST, $_GET and $_REQUEST.
2. Write a PHP script to solve the equation given below :
J=π⅔j

4


Report :
1. Write the report with results, discussion and appropriate conclusion.