SlideShare a Scribd company logo
General Error Types
           and Debugging


  Pengaturcaraan PHP




Pengaturcaraan PHP
When developing Web applications with PHP and MySQL, you end up with
potential bugs in one of four or more technologies. You could have HTML
issues, PHP problems, SQL errors, or MySQL mistakes. To be able to fix
the bug, you must first determine in what realm the bug resides.




                                                                          1
Pengaturcaraan PHP

HTML problems are often the least disruptive and the easiest to catch.
You normally know there's a problem when your layout is all messed up.

PHP errors are the ones you'll see most often, as this language will be
at the heart of your applications. PHP errors fall into three general
areas:


           Logical             Run time          Syntactical




Pengaturcaraan PHP




                                                                          2
Pengaturcaraan PHP




Pengaturcaraan PHP

SQL errors are normally a
matter of syntax, and they'll be
reported when you try to run the
query on MySQL. For example,
this is a common error:


The syntax is just wrong,
confused with the SELECT syntax
(SELECT * FROM tablename). The
right syntax is:




                                   3
Pengaturcaraan PHP




Pengaturcaraan PHP

Let's examine how to begin
debugging any problem.

Step 1
Make sure that you are running
the right page. It's altogether too
common that you try to fix a
problem and no matter what you
do, it never goes away. The
reason: you've actually been
editing a different page than you
thought.




                                      4
Pengaturcaraan PHP
Step 2
Make sure that you have saved your
latest changes.

Step 3
Make sure that you run all PHP pages
through the URL. Because PHP
requires the use of a Web server,
running any PHP code requires that you
access the page through a URL
(http://www.sitename.com/page.php or
http://localhost/page.php).

If you double-click a PHP page to open
it in a browser (or use the browser's File
| Open option), you'll see the PHP code,
not the executed result.




Pengaturcaraan PHP




                                             5
Pengaturcaraan PHP




Pengaturcaraan PHP
Step 5
Know what Web server you are
running. Similarly, some problems
and features are unique to your
Web serving application —
Apache, IIS, and PWS.

You should know which one you
are using, and which version, from
when you installed the application.




                                      6
Pengaturcaraan PHP

Step 6
Try executing pages in a different Web browser. Every Web
developer should have and use at least two Web browsers.

If you test your pages in different ones, you'll see if the problem
has to do with your script or a particular browser.




           Debugging HTML



 Pengaturcaraan PHP




                                                                      7
Pengaturcaraan PHP




Pengaturcaraan PHP




                     8
Pengaturcaraan PHP

Step 5
Test the page in another browser. PHP code is generally browser-
independent, meaning you'll get consistent results regardless of the
client. Not so with HTML. Sometimes a particular browser has a quirk
that affects the rendered page.

Running the same page in another browser is the easiest way to know if
it's an HTML problem or a browser quirk.




          Displaying PHP Errors



 Pengaturcaraan PHP




                                                                         9
Pengaturcaraan PHP




Pengaturcaraan PHP
To turn on display_errors in a script, use the ini_set() function. As its
arguments, this function takes a directive name and what setting it should
have:




Including this line in a script will turn on display_errors for that script. The
only downside is that if your script has a syntax error that prevents it from
running at all, then you'll still see a blank page.

To have PHP display errors for the entire server, edit your php.ini file,
assuming you can (unless you host your site on your own computer, it
probably won't be an option).




                                                                                   10
Pengaturcaraan PHP




Pengaturcaraan PHP




                     11
Creating Custom Error
            Handlers


   Pengaturcaraan PHP




 Pengaturcaraan PHP
Adjusting error reporting is one option for error management with your sites,
and another is to alter how PHP handles errors. You can create your own
functions that will overrule PHP's default behavior (printing them out in HTML
tags). For example,




 The set_error_handler() function determines what function handles errors.
 Feeding this function the name of another function will result in that second
 function (e.g., report_errors) being called whenever an error is
 encountered. This function (report_errors) will, at that time, receive two
 arguments — an error number and a textual error message — which can
 be used in any possible manner.




                                                                                 12
Pengaturcaraan PHP

 This function can also be written to take up to five arguments,
 the extra three being the name of the file where the error was
 found, the specific line number, and the variables that existed at
 the time of the error.




         Logging PHP Errors



Pengaturcaraan PHP




                                                                      13
Pengaturcaraan PHP
In addition to handling errors by printing them out, PHP can also log the
errors to make a permanent note of them. For this purpose, the error_log()
function instructs PHP how to file an error.




The message value should be the text of the logged error. The type
dictates how the error is logged. The destination parameter can be either
the name of a file (for log type 3) or an email address (for log type 1). The
extra headers argument is used only when sending emails (log type 1).
Both the destination and extra headers are optional.




Pengaturcaraan PHP

  The types of error logging you can use are listed here.


  Number               Meaning
  0                    The message is logged using the operating system's
                       default method.
  1                    The message is sent by email to the destination address.


  2                    The message is sent to a remote debugger (for example,
                       another server).
  3                    The message is recorded in a text file.




                                                                                  14
PHP Debugging
  Techniques


Pengaturcaraan PHP




                     15
Pengaturcaraan PHP
Error                Likely Cause
Blank Page           HTML problem, or PHP error and display_errors is off.
Parse error          Missing semicolon; unbalanced curly braces, parentheses, or
                     quotation marks; or use of an unescaped quotation mark in a string.


Empty variable       Forgot the initial $, misspelled or miscapitalized the variable name,
value                inappropriate variable scope (with functions), or the
                     register_globals setting is turned off.

Undefined variable   Reference made to a variable before it is given a value or an empty
                     variable value (see those potential causes).
Call to undefined    Misspelled function name, PHP is not configured to use that
function             function (like a MySQL function), or the document that contains the
                     function definition is not properly included.

Cannot redeclare     Two definitions of your own function exist, check within included
function             files.
Headers already      White space exists in the script before the PHP tags, data has
sent                 already been printed, or a file has been included.




 Pengaturcaraan PHP




                                                                                             16
Pengaturcaraan PHP
If PHP reports an error on the last line of your document, this is almost
always because a mismatched parenthesis, curly brace, or quotation
mark was not caught until that moment.




Pengaturcaraan PHP




                                                                            17
Pengaturcaraan PHP




Pengaturcaraan PHP
Use Comments
Just as you can use comments to document your scripts, you can also use
them to rule out problematic lines. If PHP is giving you an error on line 12,
then commenting out that line should get rid of the error. If not, then you
know the error is elsewhere.




                                                                                18
End



Pengaturcaraan PHP




                     19
Ad

More Related Content

What's hot (18)

Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
Hamad Odhabi
 
Module-4_WTA_PHP Class & Error Handling
Module-4_WTA_PHP Class & Error HandlingModule-4_WTA_PHP Class & Error Handling
Module-4_WTA_PHP Class & Error Handling
SIVAKUMAR V
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
comp274
 
Coding standards
Coding standardsCoding standards
Coding standards
BishalAryal8
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6
helpido9
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...
PVS-Studio
 
Switch statement
Switch statementSwitch statement
Switch statement
Patrick John McGee
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
talha ijaz
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
Vineet Kumar Saini
 
Creating a program from flowchart
Creating a program from flowchartCreating a program from flowchart
Creating a program from flowchart
Max Friel
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
Mahmoud Alfarra
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
sjskjd709707
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
Algorithm
AlgorithmAlgorithm
Algorithm
IHTISHAM UL HAQ
 
Quiz5
Quiz5Quiz5
Quiz5
Rifky A Ayub
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
Hamad Odhabi
 
Module-4_WTA_PHP Class & Error Handling
Module-4_WTA_PHP Class & Error HandlingModule-4_WTA_PHP Class & Error Handling
Module-4_WTA_PHP Class & Error Handling
SIVAKUMAR V
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
comp274
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6
helpido9
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...
PVS-Studio
 
Creating a program from flowchart
Creating a program from flowchartCreating a program from flowchart
Creating a program from flowchart
Max Friel
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
Mahmoud Alfarra
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
sjskjd709707
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 

Viewers also liked (20)

Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
Salim M
 
Better Design Built Faster: Using New UI Technologies to Speed Development
Better Design Built Faster: Using New UI Technologies to Speed DevelopmentBetter Design Built Faster: Using New UI Technologies to Speed Development
Better Design Built Faster: Using New UI Technologies to Speed Development
goodfriday
 
Visual Basic –User Interface- V
Visual Basic –User Interface- VVisual Basic –User Interface- V
Visual Basic –User Interface- V
Sharbani Bhattacharya
 
OS - File Handling
OS - File HandlingOS - File Handling
OS - File Handling
vinay arora
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
Wen-Tien Chang
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
Niit Care
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Active x control
Active x controlActive x control
Active x control
Amandeep Kaur
 
Ado.net
Ado.netAdo.net
Ado.net
Iblesoft
 
Ado.net
Ado.netAdo.net
Ado.net
dina1985vlr
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Farzad Wadia
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
Snehal Harawande
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
Roger Argarin
 
Oops ppt
Oops pptOops ppt
Oops ppt
abhayjuneja
 
PPT on break even analysis
PPT on break even analysisPPT on break even analysis
PPT on break even analysis
ITC Limited
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
Salim M
 
Better Design Built Faster: Using New UI Technologies to Speed Development
Better Design Built Faster: Using New UI Technologies to Speed DevelopmentBetter Design Built Faster: Using New UI Technologies to Speed Development
Better Design Built Faster: Using New UI Technologies to Speed Development
goodfriday
 
OS - File Handling
OS - File HandlingOS - File Handling
OS - File Handling
vinay arora
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
Wen-Tien Chang
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
Niit Care
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
Roger Argarin
 
PPT on break even analysis
PPT on break even analysisPPT on break even analysis
PPT on break even analysis
ITC Limited
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Ad

Similar to Error handling and debugging (20)

Basic php
Basic phpBasic php
Basic php
salissal
 
Dynamic website
Dynamic websiteDynamic website
Dynamic website
salissal
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
jeeva indra
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Roohul Amin
 
phptutorial
phptutorialphptutorial
phptutorial
tutorialsruby
 
phptutorial
phptutorialphptutorial
phptutorial
tutorialsruby
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics Ebook
Swanand Pol
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
sushil kumar
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Nguyễn Hoà
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
vigneswaran54
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
PrinceGuru MS
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
rasool noorpour
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
PHP2An introduction to Gnome.pptx.j.pptx
PHP2An introduction to Gnome.pptx.j.pptxPHP2An introduction to Gnome.pptx.j.pptx
PHP2An introduction to Gnome.pptx.j.pptx
JAYAVARSHINIJR
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
M.Zalmai Rahmani
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
Dynamic website
Dynamic websiteDynamic website
Dynamic website
salissal
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
jeeva indra
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics Ebook
Swanand Pol
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
PrinceGuru MS
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
PHP2An introduction to Gnome.pptx.j.pptx
PHP2An introduction to Gnome.pptx.j.pptxPHP2An introduction to Gnome.pptx.j.pptx
PHP2An introduction to Gnome.pptx.j.pptx
JAYAVARSHINIJR
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
Ad

More from salissal (6)

Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 
My sql
My sqlMy sql
My sql
salissal
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
salissal
 
Web application security
Web application securityWeb application security
Web application security
salissal
 
Developing web applications
Developing web applicationsDeveloping web applications
Developing web applications
salissal
 
Programming with php
Programming with phpProgramming with php
Programming with php
salissal
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
salissal
 
Web application security
Web application securityWeb application security
Web application security
salissal
 
Developing web applications
Developing web applicationsDeveloping web applications
Developing web applications
salissal
 
Programming with php
Programming with phpProgramming with php
Programming with php
salissal
 

Recently uploaded (20)

How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 

Error handling and debugging

  • 1. General Error Types and Debugging Pengaturcaraan PHP Pengaturcaraan PHP When developing Web applications with PHP and MySQL, you end up with potential bugs in one of four or more technologies. You could have HTML issues, PHP problems, SQL errors, or MySQL mistakes. To be able to fix the bug, you must first determine in what realm the bug resides. 1
  • 2. Pengaturcaraan PHP HTML problems are often the least disruptive and the easiest to catch. You normally know there's a problem when your layout is all messed up. PHP errors are the ones you'll see most often, as this language will be at the heart of your applications. PHP errors fall into three general areas: Logical Run time Syntactical Pengaturcaraan PHP 2
  • 3. Pengaturcaraan PHP Pengaturcaraan PHP SQL errors are normally a matter of syntax, and they'll be reported when you try to run the query on MySQL. For example, this is a common error: The syntax is just wrong, confused with the SELECT syntax (SELECT * FROM tablename). The right syntax is: 3
  • 4. Pengaturcaraan PHP Pengaturcaraan PHP Let's examine how to begin debugging any problem. Step 1 Make sure that you are running the right page. It's altogether too common that you try to fix a problem and no matter what you do, it never goes away. The reason: you've actually been editing a different page than you thought. 4
  • 5. Pengaturcaraan PHP Step 2 Make sure that you have saved your latest changes. Step 3 Make sure that you run all PHP pages through the URL. Because PHP requires the use of a Web server, running any PHP code requires that you access the page through a URL (http://www.sitename.com/page.php or http://localhost/page.php). If you double-click a PHP page to open it in a browser (or use the browser's File | Open option), you'll see the PHP code, not the executed result. Pengaturcaraan PHP 5
  • 6. Pengaturcaraan PHP Pengaturcaraan PHP Step 5 Know what Web server you are running. Similarly, some problems and features are unique to your Web serving application — Apache, IIS, and PWS. You should know which one you are using, and which version, from when you installed the application. 6
  • 7. Pengaturcaraan PHP Step 6 Try executing pages in a different Web browser. Every Web developer should have and use at least two Web browsers. If you test your pages in different ones, you'll see if the problem has to do with your script or a particular browser. Debugging HTML Pengaturcaraan PHP 7
  • 9. Pengaturcaraan PHP Step 5 Test the page in another browser. PHP code is generally browser- independent, meaning you'll get consistent results regardless of the client. Not so with HTML. Sometimes a particular browser has a quirk that affects the rendered page. Running the same page in another browser is the easiest way to know if it's an HTML problem or a browser quirk. Displaying PHP Errors Pengaturcaraan PHP 9
  • 10. Pengaturcaraan PHP Pengaturcaraan PHP To turn on display_errors in a script, use the ini_set() function. As its arguments, this function takes a directive name and what setting it should have: Including this line in a script will turn on display_errors for that script. The only downside is that if your script has a syntax error that prevents it from running at all, then you'll still see a blank page. To have PHP display errors for the entire server, edit your php.ini file, assuming you can (unless you host your site on your own computer, it probably won't be an option). 10
  • 12. Creating Custom Error Handlers Pengaturcaraan PHP Pengaturcaraan PHP Adjusting error reporting is one option for error management with your sites, and another is to alter how PHP handles errors. You can create your own functions that will overrule PHP's default behavior (printing them out in HTML tags). For example, The set_error_handler() function determines what function handles errors. Feeding this function the name of another function will result in that second function (e.g., report_errors) being called whenever an error is encountered. This function (report_errors) will, at that time, receive two arguments — an error number and a textual error message — which can be used in any possible manner. 12
  • 13. Pengaturcaraan PHP This function can also be written to take up to five arguments, the extra three being the name of the file where the error was found, the specific line number, and the variables that existed at the time of the error. Logging PHP Errors Pengaturcaraan PHP 13
  • 14. Pengaturcaraan PHP In addition to handling errors by printing them out, PHP can also log the errors to make a permanent note of them. For this purpose, the error_log() function instructs PHP how to file an error. The message value should be the text of the logged error. The type dictates how the error is logged. The destination parameter can be either the name of a file (for log type 3) or an email address (for log type 1). The extra headers argument is used only when sending emails (log type 1). Both the destination and extra headers are optional. Pengaturcaraan PHP The types of error logging you can use are listed here. Number Meaning 0 The message is logged using the operating system's default method. 1 The message is sent by email to the destination address. 2 The message is sent to a remote debugger (for example, another server). 3 The message is recorded in a text file. 14
  • 15. PHP Debugging Techniques Pengaturcaraan PHP 15
  • 16. Pengaturcaraan PHP Error Likely Cause Blank Page HTML problem, or PHP error and display_errors is off. Parse error Missing semicolon; unbalanced curly braces, parentheses, or quotation marks; or use of an unescaped quotation mark in a string. Empty variable Forgot the initial $, misspelled or miscapitalized the variable name, value inappropriate variable scope (with functions), or the register_globals setting is turned off. Undefined variable Reference made to a variable before it is given a value or an empty variable value (see those potential causes). Call to undefined Misspelled function name, PHP is not configured to use that function function (like a MySQL function), or the document that contains the function definition is not properly included. Cannot redeclare Two definitions of your own function exist, check within included function files. Headers already White space exists in the script before the PHP tags, data has sent already been printed, or a file has been included. Pengaturcaraan PHP 16
  • 17. Pengaturcaraan PHP If PHP reports an error on the last line of your document, this is almost always because a mismatched parenthesis, curly brace, or quotation mark was not caught until that moment. Pengaturcaraan PHP 17
  • 18. Pengaturcaraan PHP Pengaturcaraan PHP Use Comments Just as you can use comments to document your scripts, you can also use them to rule out problematic lines. If PHP is giving you an error on line 12, then commenting out that line should get rid of the error. If not, then you know the error is elsewhere. 18