Well, we see more questions here of the type ‘this doesn’t work, why not?’ than of anything else, so I’m going to give you some debugging tips. Afterall, we can’t really do anything that you can’t yourself… we just might know a little more.
First off, try to avoid coding a hundred lines of code all at once and then testing it. I know that sometimes this is unavoidable, but often times it’s possible to stop every once in awhile and test your script.
Know Your Enemy
Learn what the errors mean, that we you have an idea of what you’re looking for. I can’t find any place that lists them, but most are self explanatory.
Don’t Always Trust The Error
Sometimes PHP gets confused and prints the wrong line number for an error… or rather the wrong line for us to look at to SEE the error. See, PHP doesn’t know there is a parse error until it encounters something that it doesn’t expect, so it gives you the line number of the character(s) that were not expected.
Two examples of this are forgetting a ( and a (}). If you leave off a ( then PHP will usually say the line of code BELOW where the ( should be. If you forget a (}) then often times the error will say it is on the last line of the file.
Check Your Logic
Usually when a script doesn’t work it’s because some if statement isn’t being triggered. Well, to find out if the statement is being triggered just use a simple ‘echo’. Once you know if it’s being triggered or not then you can proceed from there. If it is being triggered and is supposed to be but the script is still not working, then the error must be somewhere inside of the if statement. If the if statement is NOT being triggered when it is supposed to be, then print out the values being compared and see if they are what you expect to find. Sometimes small differences in strings can be overlooked… such as ‘bool’ and 'bool '.
Echo/Print is Priceless
Perhaps the best debugging tools available, echo and print allow you to tell the logic your script is following and the value of anything you’re trying to compare. I use them quite heavily in debugging.
If you would like to see something added to this post, either PM me, e-mail me, or post it below. If it’s worthwhile, I’ll put it up… stealing all credit of course. :lol: