Solved

How to catch error codes when testing PHP or HTML code

Posted on 2015-01-21
4
226 Views
Last Modified: 2015-01-23
When writing some PHP scripts or HTML scripts I like to know what the mistake are when I test the script.  Is there any type of coding I can add to a PHP or HTML program that will tell me what line of code it stopped at ?
0
Comment
Question by:Scott Johnston
4 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 400 total points
ID: 40563437
HTML is not script, it's a markup language. It will either display or not display depending on the magnitude of the error and the browser's ability to correct your bad markup (most browsers are pretty good at this).

If you open an HTML page in any decent text editor that does syntax highlighting (Programmer's Notepad, Notepad++, Sublime) it will become pretty obvious where your mistakes are if the syntax is off.

For PHP, different story.  Add the following code to the top of your PHP scripts:

ini_set('display_errors',1); 
 error_reporting(E_ALL);

Open in new window


That should force the script to send any errors to the browser for your reading enjoyment.  Just make sure to remove those or comment them out before deploying the script in a production environment.
0
 

Author Comment

by:Scott Johnston
ID: 40563456
I use sublime and love it...
I testing a script for emailing info to customers.
This code help in debugging.
It worked great...I have a lot of work now.
Just to make sure the Error report starts of with NOTICE: ........................talks about what is wrong and what line number....

Thank you
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40563498
You might want to learn about Google Chrome Dev Tools.  This will take you an entire day of your life and it will put you about a year ahead of other developers who have not chosen the power.  Use the power wisely.
https://developer.chrome.com/devtools
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 40563628
For HTML and the HTML generated by PHP, there is the W3C Validator http://validator.w3.org/ which will tell you about HTML errors and non-standard syntax.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Read about why website design really matters in today's demanding market.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now