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

What's hot (20)

PDF
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
PPTX
Web design - Working with forms in HTML
Mustafa Kamel Mohammadi
 
PPT
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
PPTX
HTML Forms
Nisa Soomro
 
PPT
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
PDF
Php introduction
krishnapriya Tadepalli
 
PPT
Introduction to PHP.ppt
SanthiNivas
 
PPT
CSS for Beginners
Amit Kumar Singh
 
PPT
Arrays in PHP
Compare Infobase Limited
 
PPTX
Form using html and java script validation
Maitree Patel
 
PPTX
html forms
ikram niaz
 
PPTX
Loops PHP 04
mohamedsaad24
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
PDF
Introduction to html
eShikshak
 
PPT
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
PPTX
jQuery PPT
Dominic Arrojado
 
PPTX
Get method and post method
baabtra.com - No. 1 supplier of quality freshers
 
PDF
CSS selectors
Héla Ben Khalfallah
 
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
Web design - Working with forms in HTML
Mustafa Kamel Mohammadi
 
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
HTML Forms
Nisa Soomro
 
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Php introduction
krishnapriya Tadepalli
 
Introduction to PHP.ppt
SanthiNivas
 
CSS for Beginners
Amit Kumar Singh
 
Form using html and java script validation
Maitree Patel
 
html forms
ikram niaz
 
Loops PHP 04
mohamedsaad24
 
PHP FUNCTIONS
Zeeshan Ahmed
 
Introduction to html
eShikshak
 
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
jQuery PPT
Dominic Arrojado
 
CSS selectors
Héla Ben Khalfallah
 

Viewers also liked (20)

PPTX
3 php forms
hello8421
 
ODP
Form Processing In Php
Harit Kothari
 
PPTX
Php Form
lotlot
 
PDF
Making web forms using php
krishnapriya Tadepalli
 
PDF
Forms and Databases in PHP
Mike Crabb
 
PPSX
Php and MySQL
Tiji Thomas
 
PDF
Deliver Files With PHP
Thomas Weinert
 
DOCX
Script login form php
Hanief Rpl
 
PPT
Using arrays with PHP for forms and storing information
Nicole Ryan
 
PDF
03 the htm_lforms
IIUM
 
PPTX
Ns3
Rehmat Ullah
 
PPT
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
PDF
Memphis php html form processing with php
Joe Ferguson
 
PPTX
PHP Cookies and Sessions
Nisa Soomro
 
PDF
PHP Files: An Introduction
Jacques Woodcock
 
PPTX
PHP Forms PHP 05
mohamedsaad24
 
PPT
PHP Cookies, Sessions and Authentication
Gerard Sychay
 
PDF
ns-3: History and Future
mathieu_lacage
 
PDF
Network Simulation NS3
baddi youssef
 
PDF
Creating And Consuming Web Services In Php 5
Michael Girouard
 
3 php forms
hello8421
 
Form Processing In Php
Harit Kothari
 
Php Form
lotlot
 
Making web forms using php
krishnapriya Tadepalli
 
Forms and Databases in PHP
Mike Crabb
 
Php and MySQL
Tiji Thomas
 
Deliver Files With PHP
Thomas Weinert
 
Script login form php
Hanief Rpl
 
Using arrays with PHP for forms and storing information
Nicole Ryan
 
03 the htm_lforms
IIUM
 
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
Memphis php html form processing with php
Joe Ferguson
 
PHP Cookies and Sessions
Nisa Soomro
 
PHP Files: An Introduction
Jacques Woodcock
 
PHP Forms PHP 05
mohamedsaad24
 
PHP Cookies, Sessions and Authentication
Gerard Sychay
 
ns-3: History and Future
mathieu_lacage
 
Network Simulation NS3
baddi youssef
 
Creating And Consuming Web Services In Php 5
Michael Girouard
 
Ad

Similar to Chapter 07 php forms handling (20)

PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
PDF
Web app development_php_07
Hassen Poreya
 
PDF
PHP-Part4
Ahmed Saihood
 
PPTX
Working with data.pptx
SherinRappai
 
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PDF
web2_lec6.pdf
ssuser893014
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PDF
Form handling in php
Fahad Khan
 
PPTX
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
PPTX
forms.pptx
asmabagersh
 
PPTX
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PDF
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Chapter 08 php advance
Dhani Ahmad
 
PPTX
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PDF
Php workshop L03 superglobals
Mohammad Tahsin Alshalabi
 
PDF
Phpbasics
PrinceGuru MS
 
ODP
PHP BASIC PRESENTATION
krutitrivedi
 
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
Web app development_php_07
Hassen Poreya
 
PHP-Part4
Ahmed Saihood
 
Working with data.pptx
SherinRappai
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
Lecture7 form processing by okello erick
okelloerick
 
web2_lec6.pdf
ssuser893014
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
Form handling in php
Fahad Khan
 
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
forms.pptx
asmabagersh
 
Web Techniques like Cookies and Sessions
SonaliAbhang
 
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 08 php advance
Dhani Ahmad
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
GET and POST in PHP
Vineet Kumar Saini
 
Php workshop L03 superglobals
Mohammad Tahsin Alshalabi
 
Phpbasics
PrinceGuru MS
 
PHP BASIC PRESENTATION
krutitrivedi
 
Ad

More from Dhani Ahmad (20)

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

Recently uploaded (20)

PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PDF
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
PDF
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
PDF
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
PPTX
04_Tamás Marton_Intuitech .pptx_AI_Barometer_2025
FinTech Belgium
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PDF
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PPT
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
PPTX
05_Jelle Baats_Tekst.pptx_AI_Barometer_Release_Event
FinTech Belgium
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
PDF
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
PDF
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PPTX
SHREYAS25 INTERN-I,II,III PPT (1).pptx pre
swapnilherage
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PPTX
03_Ariane BERCKMOES_Ethias.pptx_AIBarometer_release_event
FinTech Belgium
 
PPTX
What Is Data Integration and Transformation?
subhashenia
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
04_Tamás Marton_Intuitech .pptx_AI_Barometer_2025
FinTech Belgium
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
05_Jelle Baats_Tekst.pptx_AI_Barometer_Release_Event
FinTech Belgium
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
SHREYAS25 INTERN-I,II,III PPT (1).pptx pre
swapnilherage
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
03_Ariane BERCKMOES_Ethias.pptx_AIBarometer_release_event
FinTech Belgium
 
What Is Data Integration and Transformation?
subhashenia
 

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