Solved

How to catch error codes when testing PHP or HTML code

Posted on 2015-01-21
4
233 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 109

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 83

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

813 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

18 Experts available now in Live!

Get 1:1 Help Now