SlideShare a Scribd company logo
1 of 32
Chapter 19-2
PHP
LECTUR 8:
PHP & MYSQL
PART 2
Web-Based Design
IT210
1
OBJECTIVES
By the end of this lecture student will be able to:
Apply php methodology for different SQL queries using
MySQLi extension(procedural) through interface (form)
2
OUTL
INE
3
Insert to database
through form
Display the data in a
table
Update to database
through form
Delete to database
through form
Insert , Delete , Update
1. create a connection to the database
2. verify the connection
3. create an SQL query
4. preform the Query in the database
5. verify the query (optional)
6. close the database connection (Good
practice to do so(why?))
4
PHP METHODOLOGY:
LETS WARM UP
1. Create a new database called lecture7
2. Create a table called students that has 4 column (ID , Fname, Lname ,
Email)
5
LETS WARM UP
3. Open a new php page call it lecture7.php
4. Create a form with 3 text fields and one insert button ..
3. Lets write the connection code to the database and verify it?
 Hint: in order to connect and verify our connection 3 functions are needed
 mysqli_connect(with 4 arguments);
 mysqli_connect_errno();
 mysqli_connect_error();
6
Form code is in the note ..
CONNECT TO THE DATABASE AND
VERIFY THE CONNECTION
7
Connection code is in the note
..
7
NOW,
 In the last lecture (lecture 7) we learned how to write insert code.
1. (step 3: create an insert SQL query )
2. (step 4: preform the insert Query in the database by using mysqli_query()
function )
 In (lecture 5 & 6) we learn how to deal with user input ..
Using your knowledge and based on your understanding. write a code to insert the
user inputs to the database..
8
9
insert code is in the
note ..
Select
1. create a connection to the database
2. verify the connection
3. create an SQL select query
4. preform the Query in the database
A. receive the result from the database
(As an array)
B. parse the result and use them (use
the index)
5. verify the query (optional)
6. close the database connection
10
PHP
METHODOLOGY:
NOW WE NEED TO DISPLAY ALL
RECORDS IN A HTML TABLE
 First lets make sure that select code is
working just fine …
 Lets make step (3 , 4 , a and b )
11
 Select Methodology
1. create a connection to the database
2. verify the connection
3. create an SQL select query
4. preform the Query in the database
A. receive the result from the database
(As an array)
B. parse the result and use them (use
the index)
5. verify the query (optional)
6. close the database connection
12
insert code is in the
note ..
Now lets place those in a table…
Testing select code functionality..
13
14
THE BROWSER WILL LOOK LIKE
…
Lets say , we would like to update the email of the
second record .. What should we do ?!
All the records should be pleased in a text field in
order to update them 15
pleasing the form values in an input
text field
16
Notice that when we want to display the information in text box and we need the end
user to not change the value of this field we can add readonly attribute
pleasing the form values in an input text
field (output)
17
Note: the border for the table disappear because we set the
table border to zero
UPDATING THE VALUES IN THE
FORM
18
NOW, LETS ADD A DELETE
BUTTON
 We need to add delete button on the form inside the table ..
 The code will look like…(Next Slid)
19
NOW, LETS ADD A DELETE
BUTTON
20
NOW, LETS ADD A DELETE
BUTTON
21
LETS TEST THE FORM
22
Try to insert a
record
Delete the last
record
LETS TEST THE FORM
23
Is everything
working well?
What happened? Why? How we fix it?
NO
The record will be
deleted and on the
same time
another one with
the same value
will be added
The insert value
was kept on the
supper global
array post
The page should
be reloaded
 The header() function sends a raw
HTTP header to a client.
 Return Values: This function
doesn’t return any value.
 Uses:
 Redirect the browser
THE SOLUTION IS:
PHP HEADER() FUNCTION
<?php
// PHP program to describes header function
// Redirect the browser
header(“ Location: http://www.iau.edu.sa
");
// The below code does not get executed
// while redirecting
?>
24
Where to
add?
25
header("Location:lecture7.php");
CHALLENGE YOURSELF …
26
 Add an empty fields to allow the end user to insert record in the same
table…
 NOTE: ID field should be read only .. (why?)
27
COMPLETE
SOLUTION
7
28
29
30
31
32

More Related Content

Similar to Lecture 8 PHP and MYSQL part 2.ppType Classificationtx

PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 
Ado Presentation
Ado PresentationAdo Presentation
Ado PresentationRebecca Peltz
 
1000+ php questions
1000+ php questions1000+ php questions
1000+ php questionsSandip Murari
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docxDIPESH30
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shopViditsingh22
 
Plsql task
Plsql taskPlsql task
Plsql taskNawaz Sk
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxjosephineboon366
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAlfa Gama Omega
 
Installing configuringdevelopingwithxampp
Installing configuringdevelopingwithxamppInstalling configuringdevelopingwithxampp
Installing configuringdevelopingwithxamppvimalnambiar
 
srt311 Project2
srt311 Project2srt311 Project2
srt311 Project2trayyoo
 
Lab work servlets and jsp
Lab work servlets and jspLab work servlets and jsp
Lab work servlets and jspRajiv Gupta
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5Matthew Moldvan
 
Design patterns 1july
Design patterns 1julyDesign patterns 1july
Design patterns 1julyEdureka!
 

Similar to Lecture 8 PHP and MYSQL part 2.ppType Classificationtx (20)

PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
Ado Presentation
Ado PresentationAdo Presentation
Ado Presentation
 
1000+ php questions
1000+ php questions1000+ php questions
1000+ php questions
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
 
PHP - PDO.pdf
PHP - PDO.pdfPHP - PDO.pdf
PHP - PDO.pdf
 
Php
PhpPhp
Php
 
06 procedures
06 procedures06 procedures
06 procedures
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shop
 
Plsql task
Plsql taskPlsql task
Plsql task
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
 
mush With Xampp
mush With Xamppmush With Xampp
mush With Xampp
 
Installing configuringdevelopingwithxampp
Installing configuringdevelopingwithxamppInstalling configuringdevelopingwithxampp
Installing configuringdevelopingwithxampp
 
srt311 Project2
srt311 Project2srt311 Project2
srt311 Project2
 
Soa lab
Soa lab   Soa lab
Soa lab
 
Create Components in TomatoCMS
Create Components in TomatoCMSCreate Components in TomatoCMS
Create Components in TomatoCMS
 
Lab work servlets and jsp
Lab work servlets and jspLab work servlets and jsp
Lab work servlets and jsp
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5
 
Design patterns 1july
Design patterns 1julyDesign patterns 1july
Design patterns 1july
 

More from ZahouAmel1

2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...ZahouAmel1
 
1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptxZahouAmel1
 
Lecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType ClassificationLecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType ClassificationZahouAmel1
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvZahouAmel1
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvZahouAmel1
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvZahouAmel1
 
Lec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptxLec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptxZahouAmel1
 
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptxDB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptxZahouAmel1
 
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpyDB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpyZahouAmel1
 
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxZahouAmel1
 
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptxZahouAmel1
 
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols
5-LEC- 5.pptxTransport Layer. Transport Layer ProtocolsZahouAmel1
 
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...ZahouAmel1
 
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...ZahouAmel1
 
7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork LayerZahouAmel1
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptxZahouAmel1
 
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptxZahouAmel1
 
9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink LayerZahouAmel1
 

More from ZahouAmel1 (18)

2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
 
1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx
 
Lecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType ClassificationLecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType Classification
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
Lec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptxLec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptx
 
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptxDB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
 
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpyDB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
 
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
 
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
 
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
 
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
 
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
 
7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx
 
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
 
9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Lecture 8 PHP and MYSQL part 2.ppType Classificationtx

  • 1. Chapter 19-2 PHP LECTUR 8: PHP & MYSQL PART 2 Web-Based Design IT210 1
  • 2. OBJECTIVES By the end of this lecture student will be able to: Apply php methodology for different SQL queries using MySQLi extension(procedural) through interface (form) 2
  • 3. OUTL INE 3 Insert to database through form Display the data in a table Update to database through form Delete to database through form
  • 4. Insert , Delete , Update 1. create a connection to the database 2. verify the connection 3. create an SQL query 4. preform the Query in the database 5. verify the query (optional) 6. close the database connection (Good practice to do so(why?)) 4 PHP METHODOLOGY:
  • 5. LETS WARM UP 1. Create a new database called lecture7 2. Create a table called students that has 4 column (ID , Fname, Lname , Email) 5
  • 6. LETS WARM UP 3. Open a new php page call it lecture7.php 4. Create a form with 3 text fields and one insert button .. 3. Lets write the connection code to the database and verify it?  Hint: in order to connect and verify our connection 3 functions are needed  mysqli_connect(with 4 arguments);  mysqli_connect_errno();  mysqli_connect_error(); 6 Form code is in the note ..
  • 7. CONNECT TO THE DATABASE AND VERIFY THE CONNECTION 7 Connection code is in the note .. 7
  • 8. NOW,  In the last lecture (lecture 7) we learned how to write insert code. 1. (step 3: create an insert SQL query ) 2. (step 4: preform the insert Query in the database by using mysqli_query() function )  In (lecture 5 & 6) we learn how to deal with user input .. Using your knowledge and based on your understanding. write a code to insert the user inputs to the database.. 8
  • 9. 9 insert code is in the note ..
  • 10. Select 1. create a connection to the database 2. verify the connection 3. create an SQL select query 4. preform the Query in the database A. receive the result from the database (As an array) B. parse the result and use them (use the index) 5. verify the query (optional) 6. close the database connection 10 PHP METHODOLOGY:
  • 11. NOW WE NEED TO DISPLAY ALL RECORDS IN A HTML TABLE  First lets make sure that select code is working just fine …  Lets make step (3 , 4 , a and b ) 11  Select Methodology 1. create a connection to the database 2. verify the connection 3. create an SQL select query 4. preform the Query in the database A. receive the result from the database (As an array) B. parse the result and use them (use the index) 5. verify the query (optional) 6. close the database connection
  • 12. 12 insert code is in the note .. Now lets place those in a table… Testing select code functionality..
  • 13. 13
  • 14. 14
  • 15. THE BROWSER WILL LOOK LIKE … Lets say , we would like to update the email of the second record .. What should we do ?! All the records should be pleased in a text field in order to update them 15
  • 16. pleasing the form values in an input text field 16 Notice that when we want to display the information in text box and we need the end user to not change the value of this field we can add readonly attribute
  • 17. pleasing the form values in an input text field (output) 17 Note: the border for the table disappear because we set the table border to zero
  • 18. UPDATING THE VALUES IN THE FORM 18
  • 19. NOW, LETS ADD A DELETE BUTTON  We need to add delete button on the form inside the table ..  The code will look like…(Next Slid) 19
  • 20. NOW, LETS ADD A DELETE BUTTON 20
  • 21. NOW, LETS ADD A DELETE BUTTON 21
  • 22. LETS TEST THE FORM 22 Try to insert a record Delete the last record
  • 23. LETS TEST THE FORM 23 Is everything working well? What happened? Why? How we fix it? NO The record will be deleted and on the same time another one with the same value will be added The insert value was kept on the supper global array post The page should be reloaded
  • 24.  The header() function sends a raw HTTP header to a client.  Return Values: This function doesn’t return any value.  Uses:  Redirect the browser THE SOLUTION IS: PHP HEADER() FUNCTION <?php // PHP program to describes header function // Redirect the browser header(“ Location: http://www.iau.edu.sa "); // The below code does not get executed // while redirecting ?> 24 Where to add?
  • 26. CHALLENGE YOURSELF … 26  Add an empty fields to allow the end user to insert record in the same table…  NOTE: ID field should be read only .. (why?)
  • 28. 28
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32

Editor's Notes

  1. <form method="post"> First name: <input type="text" name="Fname"> Last name: <input type="text" name="Lname"> Email: <input type="text" name="Email"> <input type="submit" name="insert" value="INSERT" > </form>
  2. <?php // Define DataBase connection ...... $host = "localhost"; $user = "root"; $password = ""; $db = “lecture7"; // Make the Connection ...... $con = mysqli_connect($host, $user, $password, $db); //verfiy the Connection if( mysqli_connect_errno()){ echo “ Connection Error:” . mysqli_connect_error(); } ?>
  3. //perform only when the user click on insert if(isset($_POST['insert'])){ // store user inputs in variables $Fname=$_POST['Fname']; $lname=$_POST['Lname']; $Email=$_POST['Email']; // step 3# create an insert sql query $sql = "INSERT INTO students (Fname, Lname, Email) VALUES ('$Fname', '$lname' ,'$Email')"; // step 4# preform the insert Query in the database by using mysqli_query() $result=mysqli_query($con, $sql); // verify the query (optional) if ($result) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } }
  4. // step 3# create a Select sql query $sql = "SELECT ID,Fname,Lname,Email FROM students"; // step 4# preform the insert Query in the database using mysqli_query() $result= mysqli_query($con, $sql); // step a & b while ($rows = mysqli_fetch_array($result)){ echo $rows['ID']. " " .$rows['Fname']. " " . $rows['Lname']. " " . $rows['Email']. " "; echo "<br>"; }
  5. <?php $host = "localhost"; $user = "root"; $password = ""; $db = "lecture11"; $con = mysqli_connect($host, $user, $password, $db); if( mysqli_connect_errno()){ echo 'Connection Error:' . mysqli_connect_error(); } //$Fname=$Lname=$Email=""; //perform only when the user click on insert if(isset($_POST['insert'])){ // store user inputs in variables $Fname=$_POST['Fname']; $lname=$_POST['Lname']; $Email=$_POST['Email']; // step 3# create an insert sql query $sql = "INSERT INTO students (Fname, Lname, Email) VALUES ('$Fname', '$lname' ,'$Email')"; // step 4# preform the insert Query in the database by using mysqli_query() $result=mysqli_query($con, $sql); // step 5# verify the query (optional) if ($result) { echo "New record created successfully <br>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } }?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Lecture 11</title> </head> <body> <form method="post"> First name: <input type="text" name="Fname"> Last name: <input type="text" name="Lname"> Email: <input type="text" name="Email"> <input type="submit" name="insert" value="INSERT" > </form> <table border="1"> <tr> <th> ID </th> <th> First Name </th> <th> Last Name </th> <th> Email </th> </tr> <?php // step 3# create a Select sql query $sql = "SELECT ID,Fname,Lname,Email FROM students"; // step 4# preform the insert Query in the database using mysqli_query() $result= mysqli_query($con, $sql); // step a & b while ($rows = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $rows['ID'] . "</td>"; echo "<td>" . $rows['Fname'] . "</td>"; echo "<td>" . $rows['Lname'] . "</td>"; echo "<td>" . $rows['Email'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> </body> </html>
  6. <?php $host = "localhost"; $user = "root"; $password = ""; $db = "lecture11"; $con = mysqli_connect($host, $user, $password, $db); if( mysqli_connect_errno()){ echo 'Connection Error:' . mysqli_connect_error(); } //$Fname=$Lname=$Email=""; //perform only when the user click on insert if(isset($_POST['insert'])){ // store user inputs in variables $Fname=$_POST['Fname']; $lname=$_POST['Lname']; $Email=$_POST['Email']; // step 3# create an insert sql query $sql = "INSERT INTO students (Fname, Lname, Email) VALUES ('$Fname', '$lname' ,'$Email')"; // step 4# preform the insert Query in the database by using mysqli_query() $result=mysqli_query($con, $sql); // step 5# verify the query (optional) if ($result) { echo "New record created successfully <br>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } }?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Lecture 11</title> </head> <body> <form method="post"> First name: <input type="text" name="Fname"> Last name: <input type="text" name="Lname"> Email: <input type="text" name="Email"> <input type="submit" name="insert" value="INSERT" > </form> <table border="1"> <tr> <th> ID </th> <th> First Name </th> <th> Last Name </th> <th> Email </th> </tr> <?php // step 3# create a Select sql query $sql = "SELECT ID,Fname,Lname,Email FROM students"; // step 4# preform the insert Query in the database using mysqli_query() $result= mysqli_query($con, $sql); // step a & b while ($rows = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $rows['ID'] . "</td>"; echo "<td>" . $rows['Fname'] . "</td>"; echo "<td>" . $rows['Lname'] . "</td>"; echo "<td>" . $rows['Email'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> </body> </html>
  7. // step a & b while ($rows = mysqli_fetch_array($result)){ echo"<form method ='post'>"; echo "<tr>"; echo "<td>" . "<input type='text' name='id' value=" . $rows['ID'] . " readonly></td>"; echo "<td>" . "<input type='text' name='fname' value= " . $rows['Fname'] . "></td>"; echo "<td>" . "<input type='text' name='lname' value= ". $rows['Lname'] . "></td>"; echo "<td>" . "<input type='email' name='email' value=" . $rows['Email'] . "></td>"; echo "<td>" . "<input type='submit' name='update' value='update'>" . "</td>"; echo "</tr>"; echo "</form>"; }
  8. //perform only when the user click on update if(isset($_POST['update'])){ $sql="UPDATE students SET Fname='$_POST[fname]' , Lname= '$_POST[lname]' ,Email='$_POST[email]' WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "updated"; }else{ echo "wasn't able to make the required update"; } }
  9. while ($rows = mysqli_fetch_array($result)){ echo"<form method ='post'>"; echo "<tr>"; echo "<td>" . "<input type='text' name='id' value=" . $rows['ID'] . " readonly></td>"; echo "<td>" . "<input type='text' name='fname' value= " . $rows['Fname'] . "></td>"; echo "<td>" . "<input type='text' name='lname' value= ". $rows['Lname'] . "></td>"; echo "<td>" . "<input type='email' name='email' value=" . $rows['Email'] . "></td>"; echo "<td>" . "<input type='submit' name='update' value='update'>" . "</td>"; echo "<td>" . "<input type='submit' name='Delete' value='Delete'>" . "</td>"; echo "</tr>"; echo "</form>"; } echo "</table>";
  10. //perform only when the user click on Delete if(isset($_POST['Delete'])){ $sql="DELETE FROM students WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "DELETED"; }else{ echo "wasn't able to make the required delete"; } }
  11. //perform only when the user click on insert if(isset($_POST['insert'])){ // store user inputs in variables $Fname=$_POST['Fname']; $lname=$_POST['Lname']; $Email=$_POST['Email']; // step 3# create an insert sql query $sql = "INSERT INTO students (Fname, Lname, Email) VALUES ('$Fname', '$lname' ,'$Email')"; // step 4# preform the insert Query in the database by using mysqli_query() $result=mysqli_query($con, $sql); // verify the query (optional) if ($result) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } }
  12. <?php $host = "localhost"; $user = "root"; $password = ""; $db = "lecture7"; $con = mysqli_connect($host, $user, $password, $db); if( mysqli_connect_errno()){ echo 'Connection Error:' . mysqli_connect_error(); } //perform only when the user click on update if(isset($_POST['update'])){ $sql="UPDATE students SET Fname='$_POST[fname]' , Lname= '$_POST[lname]' ,Email='$_POST[email]' WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "updated"; }else{ echo "wasn't able to make the required update"; } } //perform only when the user click on Delete if(isset($_POST['Delete'])){ $sql="DELETE FROM students WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "DELETED"; }else{ echo "wasn't able to make the required delete"; } } //perform only when the user click on insert if(isset($_POST['insert'])){ // store user inputs in variables $Fname=$_POST['Fname']; $lname=$_POST['Lname']; $Email=$_POST['Email']; // step 3# create an insert sql query $sql = "INSERT INTO students (Fname, Lname, Email) VALUES ('$Fname', '$lname' ,'$Email')"; // step 4# preform the insert Query in the database by using mysqli_query() $result=mysqli_query($con, $sql); // step 5# verify the query (optional) if ($result) { echo "New record created successfully <br>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } }?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Lecture 11</title> </head> <body> <table border="0"> <tr> <th> ID </th> <th> First Name </th> <th> Last Name </th> <th> Email </th> </tr> <?php // step 3# create a Select sql query $sql = "SELECT ID,Fname,Lname,Email FROM students"; // step 4# preform the insert Query in the database using mysqli_query() $result= mysqli_query($con, $sql); // step a & b while ($rows = mysqli_fetch_array($result)){ echo"<form method ='post'>"; echo "<tr>"; echo "<td>" . "<input type='text' name='id' value=" . $rows['ID'] . " readonly></td>"; echo "<td>" . "<input type='text' name='fname' value= " . $rows['Fname'] . "></td>"; echo "<td>" . "<input type='text' name='lname' value= ". $rows['Lname'] . "></td>"; echo "<td>" . "<input type='email' name='email' value=" . $rows['Email'] . "></td>"; echo "<td>" . "<input type='submit' name='update' value='update'>" . "</td>"; echo "<td>" . "<input type='submit' name='Delete' value='Delete'>" . "</td>"; echo "</tr>"; echo "</form>"; } echo "<form method='post'>"; echo "<tr>"; echo "<td>" . "<input type='text' readonly>". "</td>" ; echo "<td>" . "<input type='text' name='Fname'>". "</td>" ; echo "<td>" . "<input type='text' name='Lname'>". "</td>" ; echo "<td>" . "<input type='email' name='Email'>". "</td>" ; echo "<td colspan=2>" . "<input type='submit' name='insert' value='INSERT' >". "</td>" ; echo "</tr>"; echo "</form>"; echo "</table>"; ?> </body> </html>