SlideShare a Scribd company logo
Sending Values
         Manually


Pengaturcaraan PHP




Pengaturcaraan PHP
In the examples so far, all of the data received in the PHP script came from
what the user entered in a form. There are, however, two different ways
you can pass variables and values to a PHP script, both worth knowing.

The first method is to make use of HTML's hidden input type:




                                                                               1
Pengaturcaraan PHP

The second method is to append a value to the PHP script's URL:




This technique emulates the GET method of an HTML form. With this
specific example, page.php receives a variable called $_GET['name'] with a
value of Brian.

To demonstrate this GET method trick, a new version of the view_users.php
script will be written. This one will provide links to edit or delete an existing
user. The links will pass the user's ID to the handling pages, both of which
will be written subsequently.




                                                                                    2
Pengaturcaraan PHP

Step 2
Change the SQL query as follows.




 We have changed this query in a couple of ways. First, we select the first
 and last names as separate values, instead of as one concatenated value.
 Second, we now also select the user_id value, which will be necessary in
 creating the links.




 Pengaturcaraan PHP
 Step 3
 Add three more columns to the
 main table.

 In the previous version of the
 script, there were only two
 columns: one for the name and
 another for the date the user
 registered. We've separated
 out the name column into its
 two parts and created one
 column for the Edit link and
 another for the Delete link.




                                                                              3
Pengaturcaraan PHP
Step 4
Change the echo statement within
the while loop to match the table's
new structure.


For each record returned from
the database, this line will print
out a row with five columns. The
last three columns are obvious
and easy to create: just refer to
the returned column name.




 Pengaturcaraan PHP

For the first two columns,
which provide links to edit or
delete the user, the syntax is
slightly more complicated. The
desired end result is HTML
code like <a
href="edit_user.php?id=X">Edi
t</a>, where X is the user's ID.
Having established this, all we
have to do is print
$row['user_id'] for X, being
mindful of the quotation marks
to avoid parse errors.




                                      4
Pengaturcaraan PHP




    Using Hidden Form
    Inputs


Pengaturcaraan PHP




                        5
Pengaturcaraan PHP

  Step 1
  Create a new PHP document in your text editor or IDE.




Pengaturcaraan PHP
Step 2
Include the page header. This document will use the same template system
as the other pages in the application.




                                                                           6
Pengaturcaraan PHP
Step 3
Check for a valid user ID value.




Pengaturcaraan PHP

Step 4
Include the MySQL connection script.




                                       7
Pengaturcaraan PHP

Step 5
Begin the main submit conditional.




Pengaturcaraan PHP

Step 6
Delete the user, if appropriate.




                                     8
Pengaturcaraan PHP




Pengaturcaraan PHP

Step 7
Check if the deletion worked and respond accordingly.




                                                        9
Pengaturcaraan PHP
Step 11
Display the form. First, the database information is retrieved using the
mysql_fetch_array() function. Then the form is printed, showing the name
value retrieved from the database at the top. An important step here is
that the user ID ($id) is stored as a hidden form input so that the
handling process can also access this value.




 Pengaturcaraan PHP




                                                                           10
Editing Existing
          Records


 Pengaturcaraan PHP




Pengaturcaraan PHP
Step 1
Create a new PHP document in your text editor or IDE.




                                                        11
Pengaturcaraan PHP
Step 3
Include the MySQL connection script and begin the main submit conditional.




Pengaturcaraan PHP
Step 4
Validate the form data.




                                                                             12
Pengaturcaraan PHP




Pengaturcaraan PHP
Step 6
Update the database.




                       13
Pengaturcaraan PHP
Display the form. The form has but three text inputs, each of which is made
sticky using the data retrieved from the database. The user ID ($id) is stored
as a hidden form input so that the handling process can also access this
value.




            Paginating Query
            Results


   Pengaturcaraan PHP




                                                                                 14
Pengaturcaraan PHP




Pengaturcaraan PHP
Step 2
After including the database connection, set the number of
records to display per page.




                                                             15
Pengaturcaraan PHP

Step 3
Check if the number of required pages has been determined.




Pengaturcaraan PHP
Step 4
Count the number of records in the database.




                                                             16
Pengaturcaraan PHP

Step 5
Mathematically calculate how many pages are required.




Pengaturcaraan PHP

Step 6
Determine the starting point in the database.




                                                        17
Pengaturcaraan PHP

Step 7
Change the query so that it uses the LIMIT clause.




Pengaturcaraan PHP
Step 12
After completing the HTML table, begin a section for displaying links
to other pages, if necessary.




                                                                        18
Pengaturcaraan PHP




Pengaturcaraan PHP




                     19
Pengaturcaraan PHP
Step 13
Finish making the links.




Pengaturcaraan PHP




                           20
Making Sortable
           Displays


  Pengaturcaraan PHP




Pengaturcaraan PHP

Step 1
Open or create view_users.php in your text editor or IDE.




                                                            21
Pengaturcaraan PHP

Step 3
Check if a sorting order has already been determined.




Pengaturcaraan PHP
Step 4
Begin defining a switch conditional that determines how the
results should be sorted.




                                                              22
Pengaturcaraan PHP
Step 5
Complete the switch
conditional. There are six
total conditions to check
against, plus the default
(just in case). For each the
$order_by variable is
defined as it will be used in
the query and the
appropriate link is
redefined. Since each link
has already been given a
default value (Step 2), we
only need to change a
single link's value for each
case.




Pengaturcaraan PHP

 Step 6
 Complete the isset() conditional.




                                     23
Pengaturcaraan PHP
Step 7
Modify the query to use the new $order_by variable.




Pengaturcaraan PHP
Step 8
Modify the table header echo statement to create links out of the column
headings.




                                                                           24
Pengaturcaraan PHP

Step 9
Modify the echo statement that creates the Previous link so that the sort
value is also passed.




Pengaturcaraan PHP

 Step 10
 Repeat Step 9 for the numbered pages and the Next link.




                                                                            25
Pengaturcaraan PHP




    Understanding HTTP
    Headers


Pengaturcaraan PHP




                         26
Pengaturcaraan PHP
HTTP (Hypertext Transfer Protocol) is the technology at the heart of the World
Wide Web because it defines the way clients and servers communicate (in
layman's terms).

PHP's built-in header() function can be used to take advantage of this protocol.
The most common example of this will be demonstrated here, when the
header() function will be used to redirect the Web browser from the current
page to another.

To use header() to redirect the Web browser, type the following:




Pengaturcaraan PHP




                                                                                   27
Pengaturcaraan PHP
You can avoid this problem using the headers_sent() function, which
checks whether or not data has been sent to the Web browser.




Pengaturcaraan PHP




                                                                      28
Pengaturcaraan PHP
Step 6
Dynamically determine the redirection URL and then call the header() function.




 header ('Location: http://' . $_SERVER['HTTP_HOST'] .
  dirname($_SERVER['PHP_SELF']) . '/newpage.php');




Pengaturcaraan PHP

Passing values
You can add name=value pairs to the URL in a header() call to pass
values to the target page. In this example, if you added this line to the
script, prior to redirection:

$url .= '?name=' . urlencode ("$fn $ln");

then the thanks.php page could greet the user by $_GET['name'].




                                                                                 29
End



Pengaturcaraan PHP




                     30

More Related Content

What's hot (20)

Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
9780538745840 ppt ch07
9780538745840 ppt ch079780538745840 ppt ch07
9780538745840 ppt ch07
Terry Yoast
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
Sankhadeep Roy
 
Word Press Help Sheet
Word Press Help SheetWord Press Help Sheet
Word Press Help Sheet
jeyakumar sengottaiyan
 
A linux mac os x command line interface
A linux mac os x command line interfaceA linux mac os x command line interface
A linux mac os x command line interface
David Walker
 
Library Project
Library ProjectLibrary Project
Library Project
Holly Sanders
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
Asha Camper Singh
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
mcantelon
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
9780538745840 ppt ch05
9780538745840 ppt ch059780538745840 ppt ch05
9780538745840 ppt ch05
Terry Yoast
 
NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
NYCCAMP 2015 Demystifying Drupal AJAX Callback CommandsNYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
Michael Miles
 
CRUD with Dojo
CRUD with DojoCRUD with Dojo
CRUD with Dojo
Eugene Lazutkin
 
Mule caching strategy with redis cache
Mule caching strategy with redis cacheMule caching strategy with redis cache
Mule caching strategy with redis cache
Priyobroto Ghosh (Mule ESB Certified)
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
okelloerick
 
235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial
homeworkping3
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
Stephan Schmidt
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
Php
PhpPhp
Php
Tohid Kovadiya
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
Pranav Sharma
 
Apps1
Apps1Apps1
Apps1
Sultan Sharif
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
9780538745840 ppt ch07
9780538745840 ppt ch079780538745840 ppt ch07
9780538745840 ppt ch07
Terry Yoast
 
A linux mac os x command line interface
A linux mac os x command line interfaceA linux mac os x command line interface
A linux mac os x command line interface
David Walker
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
mcantelon
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
9780538745840 ppt ch05
9780538745840 ppt ch059780538745840 ppt ch05
9780538745840 ppt ch05
Terry Yoast
 
NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
NYCCAMP 2015 Demystifying Drupal AJAX Callback CommandsNYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands
Michael Miles
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
okelloerick
 
235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial
homeworkping3
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
Stephan Schmidt
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
Pranav Sharma
 

Viewers also liked (16)

Dynamic website
Dynamic websiteDynamic website
Dynamic website
salissal
 
Wells Fargo HAFA Guidelines
Wells Fargo HAFA GuidelinesWells Fargo HAFA Guidelines
Wells Fargo HAFA Guidelines
practicallist
 
My sql
My sqlMy sql
My sql
salissal
 
Web application security
Web application securityWeb application security
Web application security
salissal
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debugging
salissal
 
Equator Short Sale Manual
Equator Short Sale ManualEquator Short Sale Manual
Equator Short Sale Manual
practicallist
 
Basic php
Basic phpBasic php
Basic php
salissal
 
Pfextinguisher
PfextinguisherPfextinguisher
Pfextinguisher
e'z rules
 
Hcg foods
Hcg foodsHcg foods
Hcg foods
practicallist
 
RMA - Request for mortgage assistance
RMA - Request for mortgage assistanceRMA - Request for mortgage assistance
RMA - Request for mortgage assistance
practicallist
 
Equator Short Sale Manual
Equator Short Sale ManualEquator Short Sale Manual
Equator Short Sale Manual
practicallist
 
bank of america short sale check list
bank of america short sale check listbank of america short sale check list
bank of america short sale check list
practicallist
 
List of Internet Acronyms
List of Internet AcronymsList of Internet Acronyms
List of Internet Acronyms
practicallist
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 
Test2
Test2Test2
Test2
มาลี คล้ายมาก
 
Dynamic website
Dynamic websiteDynamic website
Dynamic website
salissal
 
Wells Fargo HAFA Guidelines
Wells Fargo HAFA GuidelinesWells Fargo HAFA Guidelines
Wells Fargo HAFA Guidelines
practicallist
 
Web application security
Web application securityWeb application security
Web application security
salissal
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debugging
salissal
 
Equator Short Sale Manual
Equator Short Sale ManualEquator Short Sale Manual
Equator Short Sale Manual
practicallist
 
Pfextinguisher
PfextinguisherPfextinguisher
Pfextinguisher
e'z rules
 
RMA - Request for mortgage assistance
RMA - Request for mortgage assistanceRMA - Request for mortgage assistance
RMA - Request for mortgage assistance
practicallist
 
Equator Short Sale Manual
Equator Short Sale ManualEquator Short Sale Manual
Equator Short Sale Manual
practicallist
 
bank of america short sale check list
bank of america short sale check listbank of america short sale check list
bank of america short sale check list
practicallist
 
List of Internet Acronyms
List of Internet AcronymsList of Internet Acronyms
List of Internet Acronyms
practicallist
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 

Similar to Developing web applications (20)

PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
Edureka!
 
How to Create and Load Model in Laravel
How to Create and Load Model in LaravelHow to Create and Load Model in Laravel
How to Create and Load Model in Laravel
Yogesh singh
 
Web Server Programming - Chapter 1
Web Server Programming - Chapter 1Web Server Programming - Chapter 1
Web Server Programming - Chapter 1
Nicole Ryan
 
9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP
Terry Yoast
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
PHP Barcelona Conference
 
Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptx
ShitalGhotekar
 
Programming with php
Programming with phpProgramming with php
Programming with php
salissal
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
Rajib Ahmed
 
Php Web Development Building Dynamic Websites Web Development Series Edet
Php Web Development Building Dynamic Websites Web Development Series EdetPhp Web Development Building Dynamic Websites Web Development Series Edet
Php Web Development Building Dynamic Websites Web Development Series Edet
bamenhamvai63
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
PHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabusPHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabus
KavithaK23
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
PrinceGuru MS
 
Php 26
Php 26Php 26
Php 26
Simratpreet Singh
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
GiyaShefin
 
Web api
Web apiWeb api
Web api
udaiappa
 
Php 26
Php 26Php 26
Php 26
Simratpreet Singh
 
Synapse india basic php development part 1
Synapse india basic php development part 1Synapse india basic php development part 1
Synapse india basic php development part 1
Synapseindiappsdevelopment
 
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).pptLect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 
P mysql training in bangalore
P mysql training in bangaloreP mysql training in bangalore
P mysql training in bangalore
myTectra Learning Solutions Private Ltd
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
Edureka!
 
How to Create and Load Model in Laravel
How to Create and Load Model in LaravelHow to Create and Load Model in Laravel
How to Create and Load Model in Laravel
Yogesh singh
 
Web Server Programming - Chapter 1
Web Server Programming - Chapter 1Web Server Programming - Chapter 1
Web Server Programming - Chapter 1
Nicole Ryan
 
9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP
Terry Yoast
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
PHP Barcelona Conference
 
Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptx
ShitalGhotekar
 
Programming with php
Programming with phpProgramming with php
Programming with php
salissal
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
Rajib Ahmed
 
Php Web Development Building Dynamic Websites Web Development Series Edet
Php Web Development Building Dynamic Websites Web Development Series EdetPhp Web Development Building Dynamic Websites Web Development Series Edet
Php Web Development Building Dynamic Websites Web Development Series Edet
bamenhamvai63
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
PHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabusPHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabus
KavithaK23
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
GiyaShefin
 
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).pptLect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 

Recently uploaded (20)

How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 

Developing web applications

  • 1. Sending Values Manually Pengaturcaraan PHP Pengaturcaraan PHP In the examples so far, all of the data received in the PHP script came from what the user entered in a form. There are, however, two different ways you can pass variables and values to a PHP script, both worth knowing. The first method is to make use of HTML's hidden input type: 1
  • 2. Pengaturcaraan PHP The second method is to append a value to the PHP script's URL: This technique emulates the GET method of an HTML form. With this specific example, page.php receives a variable called $_GET['name'] with a value of Brian. To demonstrate this GET method trick, a new version of the view_users.php script will be written. This one will provide links to edit or delete an existing user. The links will pass the user's ID to the handling pages, both of which will be written subsequently. 2
  • 3. Pengaturcaraan PHP Step 2 Change the SQL query as follows. We have changed this query in a couple of ways. First, we select the first and last names as separate values, instead of as one concatenated value. Second, we now also select the user_id value, which will be necessary in creating the links. Pengaturcaraan PHP Step 3 Add three more columns to the main table. In the previous version of the script, there were only two columns: one for the name and another for the date the user registered. We've separated out the name column into its two parts and created one column for the Edit link and another for the Delete link. 3
  • 4. Pengaturcaraan PHP Step 4 Change the echo statement within the while loop to match the table's new structure. For each record returned from the database, this line will print out a row with five columns. The last three columns are obvious and easy to create: just refer to the returned column name. Pengaturcaraan PHP For the first two columns, which provide links to edit or delete the user, the syntax is slightly more complicated. The desired end result is HTML code like <a href="edit_user.php?id=X">Edi t</a>, where X is the user's ID. Having established this, all we have to do is print $row['user_id'] for X, being mindful of the quotation marks to avoid parse errors. 4
  • 5. Pengaturcaraan PHP Using Hidden Form Inputs Pengaturcaraan PHP 5
  • 6. Pengaturcaraan PHP Step 1 Create a new PHP document in your text editor or IDE. Pengaturcaraan PHP Step 2 Include the page header. This document will use the same template system as the other pages in the application. 6
  • 7. Pengaturcaraan PHP Step 3 Check for a valid user ID value. Pengaturcaraan PHP Step 4 Include the MySQL connection script. 7
  • 8. Pengaturcaraan PHP Step 5 Begin the main submit conditional. Pengaturcaraan PHP Step 6 Delete the user, if appropriate. 8
  • 9. Pengaturcaraan PHP Pengaturcaraan PHP Step 7 Check if the deletion worked and respond accordingly. 9
  • 10. Pengaturcaraan PHP Step 11 Display the form. First, the database information is retrieved using the mysql_fetch_array() function. Then the form is printed, showing the name value retrieved from the database at the top. An important step here is that the user ID ($id) is stored as a hidden form input so that the handling process can also access this value. Pengaturcaraan PHP 10
  • 11. Editing Existing Records Pengaturcaraan PHP Pengaturcaraan PHP Step 1 Create a new PHP document in your text editor or IDE. 11
  • 12. Pengaturcaraan PHP Step 3 Include the MySQL connection script and begin the main submit conditional. Pengaturcaraan PHP Step 4 Validate the form data. 12
  • 13. Pengaturcaraan PHP Pengaturcaraan PHP Step 6 Update the database. 13
  • 14. Pengaturcaraan PHP Display the form. The form has but three text inputs, each of which is made sticky using the data retrieved from the database. The user ID ($id) is stored as a hidden form input so that the handling process can also access this value. Paginating Query Results Pengaturcaraan PHP 14
  • 15. Pengaturcaraan PHP Pengaturcaraan PHP Step 2 After including the database connection, set the number of records to display per page. 15
  • 16. Pengaturcaraan PHP Step 3 Check if the number of required pages has been determined. Pengaturcaraan PHP Step 4 Count the number of records in the database. 16
  • 17. Pengaturcaraan PHP Step 5 Mathematically calculate how many pages are required. Pengaturcaraan PHP Step 6 Determine the starting point in the database. 17
  • 18. Pengaturcaraan PHP Step 7 Change the query so that it uses the LIMIT clause. Pengaturcaraan PHP Step 12 After completing the HTML table, begin a section for displaying links to other pages, if necessary. 18
  • 20. Pengaturcaraan PHP Step 13 Finish making the links. Pengaturcaraan PHP 20
  • 21. Making Sortable Displays Pengaturcaraan PHP Pengaturcaraan PHP Step 1 Open or create view_users.php in your text editor or IDE. 21
  • 22. Pengaturcaraan PHP Step 3 Check if a sorting order has already been determined. Pengaturcaraan PHP Step 4 Begin defining a switch conditional that determines how the results should be sorted. 22
  • 23. Pengaturcaraan PHP Step 5 Complete the switch conditional. There are six total conditions to check against, plus the default (just in case). For each the $order_by variable is defined as it will be used in the query and the appropriate link is redefined. Since each link has already been given a default value (Step 2), we only need to change a single link's value for each case. Pengaturcaraan PHP Step 6 Complete the isset() conditional. 23
  • 24. Pengaturcaraan PHP Step 7 Modify the query to use the new $order_by variable. Pengaturcaraan PHP Step 8 Modify the table header echo statement to create links out of the column headings. 24
  • 25. Pengaturcaraan PHP Step 9 Modify the echo statement that creates the Previous link so that the sort value is also passed. Pengaturcaraan PHP Step 10 Repeat Step 9 for the numbered pages and the Next link. 25
  • 26. Pengaturcaraan PHP Understanding HTTP Headers Pengaturcaraan PHP 26
  • 27. Pengaturcaraan PHP HTTP (Hypertext Transfer Protocol) is the technology at the heart of the World Wide Web because it defines the way clients and servers communicate (in layman's terms). PHP's built-in header() function can be used to take advantage of this protocol. The most common example of this will be demonstrated here, when the header() function will be used to redirect the Web browser from the current page to another. To use header() to redirect the Web browser, type the following: Pengaturcaraan PHP 27
  • 28. Pengaturcaraan PHP You can avoid this problem using the headers_sent() function, which checks whether or not data has been sent to the Web browser. Pengaturcaraan PHP 28
  • 29. Pengaturcaraan PHP Step 6 Dynamically determine the redirection URL and then call the header() function. header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/newpage.php'); Pengaturcaraan PHP Passing values You can add name=value pairs to the URL in a header() call to pass values to the target page. In this example, if you added this line to the script, prior to redirection: $url .= '?name=' . urlencode ("$fn $ln"); then the thanks.php page could greet the user by $_GET['name']. 29