Solved

How to catch error codes when testing PHP or HTML code

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

910 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

19 Experts available now in Live!

Get 1:1 Help Now