Syntax is the easy part. Take some courses and/or read some books on general programming theory and practice. Learn how to write modular, loosely coupled code that is easier to debug and maintain. Study the code in well established open source projects to see how they do things.
When you get frustrated, see if you can break up what you're working on into smaller parts that you can concentrate on -- and test! -- separately.
Become active in web forums like this, not just to get your specific questions answered, but to learn new things by trying to find answers to other people's questions.