SlideShare a Scribd company logo
INSERT RECORDS IN A
DATABASE
2
Form Handling
PHP - A Simple HTML Form
3
Example
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
4
Running the Example
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo
$_POST["email"]; ?>
</body>
</html>
5
GET vs. POST
Both GET and POST create an array. This array holds
key/value pairs, where keys are the names of the form controls
and values are the input data from the user.
Both GET and POST are treated as $_GET and $_POST.
These are superglobals, which means that they are always
accessible, regardless of scope - and you can access them
from any function, class or file without having to do anything
special.
$_GET is an array of variables passed to the current script via
the URL parameters.
$_POST is an array of variables passed to the current script
via the HTTP POST method.
6
When to use GET?
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. However, because the
variables are displayed in the URL, it is possible to
bookmark the page. This can be useful in some
cases.
GET may be used for sending non-sensitive data.
7
When to use POST?
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) and
has no limits on the amount of information to send.
Moreover POST supports advanced functionality
such as support for multi-part binary input while
uploading files to server.
However, because the variables are not displayed in
the URL, it is not possible to bookmark the page.
8
Getting the form data in the
PHP script
Let’s look at some PHP code to process this form.
<?php
//Check whether the form has been submitted
if(array_key_exists('send', $_POST))
{
$varMovie = $_POST['formMovie'];
$varName = $_POST['formName'];
$varGender = $_POST['formGender'];
$errorMessage = "";
// - - - snip - - -
}
?>
9
Saving the form data to a
MySQL database
There are 3 steps to interacting with
the database in this form:
Connect to the database
Construct a SQL command string
Execute the SQL command string
Practical
10

More Related Content

PPTX
Form Handling using PHP
PPT
Php forms
PDF
Making web forms using php
PPT
Chapter 07 php forms handling
PPT
PHP - Introduction to PHP Forms
PDF
Form handling in php
PPTX
PHP Form Validation Technique
DOCX
Php forms and validations by naveen kumar veligeti
Form Handling using PHP
Php forms
Making web forms using php
Chapter 07 php forms handling
PHP - Introduction to PHP Forms
Form handling in php
PHP Form Validation Technique
Php forms and validations by naveen kumar veligeti

What's hot (18)

PDF
03 the htm_lforms
PDF
Web app development_php_07
PDF
PHP Making Web Forms
ODP
Form Processing In Php
PDF
Programming with php
PPT
Pollock
PPTX
PDF
RicoAjaxEngine
PDF
Idoc script beginner guide
PPT
.NET Code Examples
PPTX
Php ch-1_server_side_scripting_basics
PPT
Database presentation
PDF
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
PPTX
Php ch-2_html_forms_and_server_side_scripting
PDF
phptut4
PPTX
Synapse india basic php development part 1
PPTX
Php and web forms
03 the htm_lforms
Web app development_php_07
PHP Making Web Forms
Form Processing In Php
Programming with php
Pollock
RicoAjaxEngine
Idoc script beginner guide
.NET Code Examples
Php ch-1_server_side_scripting_basics
Database presentation
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Php ch-2_html_forms_and_server_side_scripting
phptut4
Synapse india basic php development part 1
Php and web forms
Ad

Similar to Lecture7 form processing by okello erick (20)

PPTX
forms.pptx
PDF
PHP-Part4
PPTX
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PDF
GET and POST in PHP
PPTX
Working with data.pptx
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
PDF
Web Development Course: PHP lecture 2
PPTX
Web Techniques like Cookies and Sessions
PPTX
A179178417_21_2025_PHP Get and Post.pptx
PDF
Introduction to php web programming - get and post
ODP
RESTful Web Services with JAX-RS
PPT
PHP-04-Forms.ppt
PPT
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
PDF
Php, mysq lpart4(processing html form)
PPTX
Get and post methods in php - phpgurukul
PPTX
Web Application Development using PHP Chapter 5
PPT
Class 6 - PHP Web Programming
PPT
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
forms.pptx
PHP-Part4
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
GET and POST in PHP
Working with data.pptx
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
Web Development Course: PHP lecture 2
Web Techniques like Cookies and Sessions
A179178417_21_2025_PHP Get and Post.pptx
Introduction to php web programming - get and post
RESTful Web Services with JAX-RS
PHP-04-Forms.ppt
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
Php, mysq lpart4(processing html form)
Get and post methods in php - phpgurukul
Web Application Development using PHP Chapter 5
Class 6 - PHP Web Programming
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
Ad

More from okelloerick (11)

PPT
My sql statements by okello erick
PPT
Lecture8 php page control by okello erick
PPT
Lecture6 display data by okello erick
PPTX
Lecture5 my sql statements by okello erick
PPTX
Lecture4 php by okello erick
PPTX
Lecture3 php by okello erick
PPTX
Lecture3 mysql gui by okello erick
PPTX
Lecture2 mysql by okello erick
PPTX
Lecture1 introduction by okello erick
PPT
Data commn intro by okello erick
PPT
Computer networks--networking hardware
My sql statements by okello erick
Lecture8 php page control by okello erick
Lecture6 display data by okello erick
Lecture5 my sql statements by okello erick
Lecture4 php by okello erick
Lecture3 php by okello erick
Lecture3 mysql gui by okello erick
Lecture2 mysql by okello erick
Lecture1 introduction by okello erick
Data commn intro by okello erick
Computer networks--networking hardware

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
A comparative analysis of optical character recognition models for extracting...
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Programs and apps: productivity, graphics, security and other tools
A comparative analysis of optical character recognition models for extracting...

Lecture7 form processing by okello erick

  • 1. INSERT RECORDS IN A DATABASE
  • 2. 2 Form Handling PHP - A Simple HTML Form
  • 3. 3 Example <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
  • 4. 4 Running the Example <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body> </html>
  • 5. 5 GET vs. POST Both GET and POST create an array. This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user. Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. $_GET is an array of variables passed to the current script via the URL parameters. $_POST is an array of variables passed to the current script via the HTTP POST method.
  • 6. 6 When to use GET? 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. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. GET may be used for sending non-sensitive data.
  • 7. 7 When to use POST? 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) and has no limits on the amount of information to send. Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to server. However, because the variables are not displayed in the URL, it is not possible to bookmark the page.
  • 8. 8 Getting the form data in the PHP script Let’s look at some PHP code to process this form. <?php //Check whether the form has been submitted if(array_key_exists('send', $_POST)) { $varMovie = $_POST['formMovie']; $varName = $_POST['formName']; $varGender = $_POST['formGender']; $errorMessage = ""; // - - - snip - - - } ?>
  • 9. 9 Saving the form data to a MySQL database There are 3 steps to interacting with the database in this form: Connect to the database Construct a SQL command string Execute the SQL command string