Learning to write code was one of the most exciting, and yet intimidating, challenges that I've faced in library systems work. Not only are there many languages out there in which to write code, all with strong and weak points in specific contexts, but each language is a large entity to grasp. I think it is somewhat important to note that two separate challenges exist. One is the process of designing the logic, which is on the whole independent of the programming language and the other is the writing of the script - that is, embodying the logic in a specific programming language.
I use a variety of resources to learn a language, typically using them as references. Most languages have a web site with a user guide/manual, like PHP's http://www.php.net/. This is the primary authority. Then tutorial-based web sites such as http://www.w3schools.com/ are very handy. Formal books are diverse. My favorites are usually published by O'Reilly, a publisher with which I became familiar during my MLIS studies, as some of my texts were their work. Lastly, on specific issues I frequently conduct internet searches and often end up reading discussion forums where practitioners help each other online. My preferred forum is http://stackoverflow.com
As I said before, knowing where to find the answers is key.