Lots of great answers already here. I just wanted to point one thing out: If you're brand new, then of course you're making dumb mistakes. You're a beginner. If you were just starting to learn a musical instrument, or playing baseball for the first time, or any other skill, you'd be pretty clumsy at that too. It's a normal, expected part of the learning process, and everyone goes through it. As the old joke goes, you do things right by experience, and you gain experience by doing things wrong.
To become truly good at any skill generally requires about ten years or 10,000 hours of serious practice in which you're constantly pushing yourself to learn and grow. If you're willing to put in the time and effort, you'll come out the other side as a good programmer.
I think the difference is that in programming, the basic tools are freely available to anyone these days (pretty much everyone has a computer an an Internet connection) and that and a few Google searches is all you need to get started writing very simple code that doesn't accomplish anything useful. It's the moral equivalent of learning to play "Hot Cross Buns" on a flute, but to do that, you need to actually go out of your way to obtain a flute, get the music, and memorize a bunch of finger positions to make the notes. But for programming, you've already got a computer, and all you need is to download a compiler, copy and paste some code that someone else wrote, and you've got a working program! No actual understanding required! So people think "Oh, wow, this programming stuff is easy!" And then when they run into their first real problem, they have no idea how to solve it and they get discouraged.
When you get down to it, programming is really only two basic skills: breaking down a large problem into smaller problems, and expressing small problems correctly in formal logic. A lot of the experience that goes into making someone a good coder lies in learning to recognize and solve a wide variety of small problems.
Today, I can get a request to implement a new feature, and I look at it and say "OK, this involves sorting a list, this part is an associative mapping, I'll need recursion for this part over here, and storing it to the database will require two tables with a foreign-key relationship." Those are all things I've learned how to do over the years, and I've learned how to recognize which techniques are appropriate for which types of problems.
If you study coding with a conscious effort to learning new ways to break down problems into smaller problems and new techniques for solving different types of small problems, you'll find that it becomes more interesting and more rewarding. And you'll find that your problems with logic-based issues go away as you learn to deal with them. (But you'll also find that you get asked to solve harder problems. It'll always be a challenge, and if it's not, you're doing it wrong.) :)
And when you run across something that stumps you, ask on StackOverflow. There are thousands of programmers who have already put in their ten years and then some, and we're willing to help out and lend a hand, especially to those who are serious about learning.