Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: PHP Error Handling Eek! Errors! - Common PHP Errors and How to Fix Them Tutorial

Explains most common PHP errors, and how you might go about fixing them. Includes Parse Errors, mySQL errors and more.

Tutorial Details:

J-Tutorials v2.0

Explains common PHP errors, and how you might go about fixing them.
Errors can be very annoying in PHP - very annoying. Especially when you have hundreds, even thousands of lines to go through. This tutorial will give some of the more common errors you tend to get in PHP, and the things that might be causing them.

OK, first thing, have a look at this error:
Parse error: parse error in d:\server\www\tests\test1.php on line 452
Parse error on line 452. If you are using Notepad to view your code, or a similar text editor, you are going to have to count down 452 lines before you get close to where your error is - and that is going to be tedious. There IS a way in Notepad (only on XP I think), to get the line number when you click on it (View -> Status Bar -> Look at bottom right), but it is still easier to get a proper PHP editor. I have found one that I like, and it is called ConTEXT (click on the link to go to the website). It is a programmers editor, with code highlighting, line numbers, etc. Very good. If you don't want to download software, or you already have some software you are happy with, you can just ignore the above bit.

Right, lets get on with the tutorial. The first, most common error in PHP is of course, the infamous Parse Error. A parse error is when you have not closed something on your script correctly (you might have forgotted a quotation mark at the end of an echo statement, or maybe you forgot your semicolon at the end of a line.

They are easily fixed (although when you have been coding for 12 hours straight, your eyes go fuzzy and you can't see where you've gone wrong!). Find the line that it says the error is on. Have a good look at it, maybe highlight just that line so it's easier to read. Have you forgotten your quotes? Check for a semi-colon at the end of the line. Check that semi-colon isn't actually a colon (they look very similar). If everything seems to be in the right place, maybe it is something less obvious, maybe you've forgotten a curly bracket (}). If everything seems to be in order there, then you need to read this: when it says the error occured on a certain line - it doesnt necacarily means the error is on that line. So in theory the error could be anywhere above that line (although usually it is only one or two lines, when it is anything at all). My advice on parse errors is just give the area of code near that line a good look at, you will get it eventually.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
PHP Error Handling Eek! Errors! - Common PHP Errors and How to Fix Them Tutorial

View Tutorial:
PHP Error Handling Eek! Errors! - Common PHP Errors and How to Fix Them Tutorial

Related Tutorials:

Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.