Put debug lines in your code, or even better a debug function. You can also suppress PHP's warnings with an @ character in front of each function (good for custom error messages).]
For SQL printing the statement out before sending to the parser often helps pick out errors. I use print_r() alot when doing more complicated hashes.
Use a good text editor with a colour scheme that highlights errors easily.
Everything else is just down to hard work 🙂