the best thing I ever learned was to get paid up front, before you do the actuall work, or at halfway done.
It depends on the size of the project. If it's a very small project, $500 or less, it's best to wait until you've done what you've committed to doing, and then recieve payment upon completion. If you're worried about getting paid for even small projects, then you should be using a site like rentacoder.com or elance.com. They will put money in an escrow account to make sure you get paid as long as you've met your part of the agreement. If the project gets a bit larger, then setting up milestones and setting up an agreement to receive a portion of payment as each milestone is met is a good way to go. Good luck in your future projects. It's a learning process and not everyone is honest, but most people are, so don't paint everyone as a potential criminal just because you got screwed a time or two by someone with very few scruples.
Sounds sad... What I do is asking to pay 100% in advance, however, the customer can see testimonials and sample works. The point is that I'm using 2checkout service, and in case the customer doesn't like the work, he can issue a refund ;-) (it seems like he has 30 days to ask for refund) and 2checkout does it, whether I want it or not. Still, there are some customers who order, pay money, get work, and then ask for refund ;-/ But it's a risk internet business faces ;-/