SlideShare a Scribd company logo
2
Most read
6
Most read
17
Most read
PHP Form HandlingPHP Form Handling
Chapter 7
MOHAMAD RAHIMI MOHAMAD
ROSMAN
PHP Forms and User InputPHP Forms and User Input
The PHP $_GET and $_POST variables are
used to retrieve information from forms,
like user input.
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.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
Create 2 new text document.
Rename the document to index.php and
welcome.php
Open the index.php
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Step 1: Write Form scriptStep 1: Write Form script
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The example HTML page above contains two input fields and a submit button.
When the user fills in this form and click on the submit button, the form data is
sent to the "welcome.php" file.
Step 2: Write PHP CodeStep 2: Write PHP Code
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Then, copy both file, paste into www folder, and start the website. What kind
of output do you get?
Form ValidationForm Validation
User input should be validated on the browser
whenever possible (by client scripts
(JavaScript)). Browser validation is faster and
you reduce the server load.
You should consider using server validation if the
user input will be inserted into a database. A
good way to validate a form on the server is to
post the form to itself, instead of jumping to a
different page.
The user will then get the error messages on the
same page as the form. This makes it easier to
discover the error.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The $_GET VariableThe $_GET Variable
The $_GET variable is an array of variable
names and values sent by the HTTP GET
method.
The $_GET variable is used to collect
values from a form with method="get".
Information sent from a form with the
GET method is visible to everyone (it will
be displayed in the browser's address bar)
and it has limits on the amount of
information to send (max. 100
characters).
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The $_GET VariableThe $_GET Variable
When using the $_GET variable all
variable names and values are displayed
in the URL.
So this method should not be used when
sending passwords or other sensitive
information!
However, because the variables are
displayed in the URL, it is possible to
bookmark the page. This can be useful in
some cases.
Note: The HTTP GET method is not
suitable on large variable values; the
value cannot exceed 100 characters.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
Create new text document.
Rename it to index.php and welcome.php
Open index.php and write the following
code.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Step 1: Write Form ScriptStep 1: Write Form Script
The code is just similar to previous
method, just change the POST to GET
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Step 2Step 2
Try to work on your own on how to
retrieve the values.
Refer to previous welcome.php for clue.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
This is the address bar with $_GET method
The $_POST VariableThe $_POST Variable
The $_POST variable is an array of
variable names and values sent by the
HTTP POST method.
The $_POST variable is used to collect
values from a form with method="post".
Information sent from a form with the
POST method is invisible to others and
has no limits on the amount of
information to send.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
This is the address bar with $_POST method
Why use $_POST?Why use $_POST?
Variables sent with HTTP POST are not
shown in the URL
Variables have no length limit
However, because the variables are not
displayed in the URL, it is not possible to
bookmark the page.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExerciseExercise
MOHAMAD RAHIMI MOHAMAD
ROSMAN
For this exercise, you can used the
following functions:
◦ Array – to store username and password
◦ Looping- to compare password
◦ PHP Form Handling – to get username and
password from users.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
11stst
StepStep
1st
Step
◦ Create a form, like the picture below. You can
name the file as index.php
MOHAMAD RAHIMI MOHAMAD
ROSMAN
22ndnd
StepStep
Username Password
Admin Admin
User 1234
Guest Guest
MOHAMAD RAHIMI MOHAMAD
ROSMAN
•Now, create a second PHP file. Name it “process.php”.
•Then, create an array, consisting of the information in the above table.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
PHP Form Handling
Use array,
looping and
if..else statement
OutPutOutPut
POST n GET
MOHAMAD RAHIMI MOHAMAD
ROSMAN
MOHAMAD RAHIMI MOHAMAD
ROSMAN

More Related Content

PPTX
Introduction to ASP.NET
PPT
XSLT.ppt
PPTX
Cascading Style Sheet (CSS)
PPTX
Php.ppt
PPTX
Html formatting
PPT
Php forms
PPTX
Form Handling using PHP
Introduction to ASP.NET
XSLT.ppt
Cascading Style Sheet (CSS)
Php.ppt
Html formatting
Php forms
Form Handling using PHP

What's hot (20)

PPT
javaScript.ppt
PPTX
Uploading a file with php
PPTX
HTML: Tables and Forms
DOCX
Php forms and validations by naveen kumar veligeti
PDF
Introduction to HTML5
PPTX
PHP FUNCTIONS
PDF
Web Development Course: PHP lecture 1
PPT
Introduction to JavaScript (1).ppt
PDF
jQuery for beginners
PPTX
Form Validation in JavaScript
PPTX
Dhtml
PPT
introduction to web technology
PPTX
Css types internal, external and inline (1)
PPTX
Introduction to php
PPTX
Javascript operators
PPT
PPT on Basic HTML Tags
javaScript.ppt
Uploading a file with php
HTML: Tables and Forms
Php forms and validations by naveen kumar veligeti
Introduction to HTML5
PHP FUNCTIONS
Web Development Course: PHP lecture 1
Introduction to JavaScript (1).ppt
jQuery for beginners
Form Validation in JavaScript
Dhtml
introduction to web technology
Css types internal, external and inline (1)
Introduction to php
Javascript operators
PPT on Basic HTML Tags
Ad

Viewers also liked (20)

PPTX
3 php forms
ODP
Form Processing In Php
PPTX
Php Form
PDF
Making web forms using php
PDF
Forms and Databases in PHP
PPSX
Php and MySQL
PDF
Deliver Files With PHP
DOCX
Script login form php
PPT
Using arrays with PHP for forms and storing information
PDF
03 the htm_lforms
PPTX
PPT
PHP - Introduction to PHP Cookies and Sessions
PDF
Memphis php html form processing with php
PPTX
PHP Cookies and Sessions
PDF
PHP Files: An Introduction
PPTX
PHP Forms PHP 05
PPT
PHP Cookies, Sessions and Authentication
PDF
ns-3: History and Future
PDF
Network Simulation NS3
PDF
Creating And Consuming Web Services In Php 5
3 php forms
Form Processing In Php
Php Form
Making web forms using php
Forms and Databases in PHP
Php and MySQL
Deliver Files With PHP
Script login form php
Using arrays with PHP for forms and storing information
03 the htm_lforms
PHP - Introduction to PHP Cookies and Sessions
Memphis php html form processing with php
PHP Cookies and Sessions
PHP Files: An Introduction
PHP Forms PHP 05
PHP Cookies, Sessions and Authentication
ns-3: History and Future
Network Simulation NS3
Creating And Consuming Web Services In Php 5
Ad

Similar to Chapter 07 php forms handling (20)

PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
PDF
Web app development_php_07
PDF
PHP-Part4
PPTX
Working with data.pptx
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PPT
Lecture7 form processing by okello erick
PDF
web2_lec6.pdf
PPT
Class 6 - PHP Web Programming
PDF
Form handling in php
PPTX
Web Application Development using PHP Chapter 5
PPTX
forms.pptx
PPTX
Web Techniques like Cookies and Sessions
PDF
PHP Loops and PHP Forms
PPT
PHP - Introduction to PHP Forms
PDF
Introduction to php web programming - get and post
PPT
Chapter 08 php advance
PPTX
Quick beginner to Lower-Advanced guide/tutorial in PHP
PDF
GET and POST in PHP
PDF
Php workshop L03 superglobals
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
Web app development_php_07
PHP-Part4
Working with data.pptx
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Lecture7 form processing by okello erick
web2_lec6.pdf
Class 6 - PHP Web Programming
Form handling in php
Web Application Development using PHP Chapter 5
forms.pptx
Web Techniques like Cookies and Sessions
PHP Loops and PHP Forms
PHP - Introduction to PHP Forms
Introduction to php web programming - get and post
Chapter 08 php advance
Quick beginner to Lower-Advanced guide/tutorial in PHP
GET and POST in PHP
Php workshop L03 superglobals

More from Dhani Ahmad (20)

PPT
Strategic planning
PPT
Strategic information system planning
PPT
Opportunities, threats, industry competition, and competitor analysis
PPT
Information system
PPT
Information resource management
PPT
Types of islamic institutions and records
PPT
Islamic information seeking behavior
PPT
Islamic information management
PPT
Islamic information management sources in islam
PPT
The need for security
PPT
The information security audit
PPT
Security technologies
PPT
Security policy
PPT
Security and personnel
PPT
Secure
PPT
Risk management ii
PPT
Risk management i
PPT
Privacy & security in heath care it
PPT
Physical security
PPT
Legal, ethical & professional issues
Strategic planning
Strategic information system planning
Opportunities, threats, industry competition, and competitor analysis
Information system
Information resource management
Types of islamic institutions and records
Islamic information seeking behavior
Islamic information management
Islamic information management sources in islam
The need for security
The information security audit
Security technologies
Security policy
Security and personnel
Secure
Risk management ii
Risk management i
Privacy & security in heath care it
Physical security
Legal, ethical & professional issues

Recently uploaded (20)

PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PDF
Lecture1 pattern recognition............
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
Database Infoormation System (DBIS).pptx
PPTX
IB Computer Science - Internal Assessment.pptx
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
Introduction to machine learning and Linear Models
PDF
Clinical guidelines as a resource for EBP(1).pdf
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Lecture1 pattern recognition............
STERILIZATION AND DISINFECTION-1.ppthhhbx
Galatica Smart Energy Infrastructure Startup Pitch Deck
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
Fluorescence-microscope_Botany_detailed content
Introduction to Knowledge Engineering Part 1
Database Infoormation System (DBIS).pptx
IB Computer Science - Internal Assessment.pptx
.pdf is not working space design for the following data for the following dat...
climate analysis of Dhaka ,Banglades.pptx
oil_refinery_comprehensive_20250804084928 (1).pptx
Data_Analytics_and_PowerBI_Presentation.pptx
Introduction to machine learning and Linear Models
Clinical guidelines as a resource for EBP(1).pdf

Chapter 07 php forms handling

  • 1. PHP Form HandlingPHP Form Handling Chapter 7 MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 2. PHP Forms and User InputPHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. 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. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 3. ExampleExample Create 2 new text document. Rename the document to index.php and welcome.php Open the index.php MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 4. Step 1: Write Form scriptStep 1: Write Form script MOHAMAD RAHIMI MOHAMAD ROSMAN The example HTML page above contains two input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the "welcome.php" file.
  • 5. Step 2: Write PHP CodeStep 2: Write PHP Code MOHAMAD RAHIMI MOHAMAD ROSMAN Then, copy both file, paste into www folder, and start the website. What kind of output do you get?
  • 6. Form ValidationForm Validation User input should be validated on the browser whenever possible (by client scripts (JavaScript)). Browser validation is faster and you reduce the server load. You should consider using server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 7. The $_GET VariableThe $_GET Variable The $_GET variable is an array of variable names and values sent by the HTTP GET method. The $_GET variable is used to collect values from a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and it has limits on the amount of information to send (max. 100 characters). MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 8. The $_GET VariableThe $_GET Variable When using the $_GET variable all variable names and values are displayed in the URL. So this method should not be used when sending passwords or other sensitive information! However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. Note: The HTTP GET method is not suitable on large variable values; the value cannot exceed 100 characters. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 9. ExampleExample Create new text document. Rename it to index.php and welcome.php Open index.php and write the following code. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 10. Step 1: Write Form ScriptStep 1: Write Form Script The code is just similar to previous method, just change the POST to GET MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 11. Step 2Step 2 Try to work on your own on how to retrieve the values. Refer to previous welcome.php for clue. MOHAMAD RAHIMI MOHAMAD ROSMAN This is the address bar with $_GET method
  • 12. The $_POST VariableThe $_POST Variable The $_POST variable is an array of variable names and values sent by the HTTP POST method. The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. MOHAMAD RAHIMI MOHAMAD ROSMAN This is the address bar with $_POST method
  • 13. Why use $_POST?Why use $_POST? Variables sent with HTTP POST are not shown in the URL Variables have no length limit However, because the variables are not displayed in the URL, it is not possible to bookmark the page. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 15. For this exercise, you can used the following functions: ◦ Array – to store username and password ◦ Looping- to compare password ◦ PHP Form Handling – to get username and password from users. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 16. 11stst StepStep 1st Step ◦ Create a form, like the picture below. You can name the file as index.php MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 17. 22ndnd StepStep Username Password Admin Admin User 1234 Guest Guest MOHAMAD RAHIMI MOHAMAD ROSMAN •Now, create a second PHP file. Name it “process.php”. •Then, create an array, consisting of the information in the above table.
  • 18. MOHAMAD RAHIMI MOHAMAD ROSMAN PHP Form Handling Use array, looping and if..else statement
  • 19. OutPutOutPut POST n GET MOHAMAD RAHIMI MOHAMAD ROSMAN