The first thing that every young and hopeful wizard must do in order to make sure his or her spells work is to really believe that magic real. If there's even a tiny bit of doubt, the spell usually won't work, sadly, and that's what trips up many a young wizard. Many people believe that magic really does exist, and that it can be created with the right mindset and a positive will. Of course, there are many different kinds of real magic, which isn't really how Hollywood or popular fantasy books portrays it as.
Also, there are literally hundreds of thousands of spells contained within thousands of spell books that can be found today. Wizards who wished to cast many of these spells often pulled out a book of spells to learn a particular one. Often, the wizard or spell caster would practice the spell several times before actually performing it for real. This is because a poorly-cast spell might not work, or if it did, might actually do harm to the wizard.
This is maybe why many people think that learning to cast a magic spell is as simple as reading from a book, but that's only a very small part of what it takes to properly cast one. Using a spell requires having dedication and deep belief in the properties of the spell, for one. And it can take years of practice and training under a master before a new wizard might be ready to cast a difficult spell.
There are many different types of magic spells, too, with some having to do with bringing about success, for example. Other spells are used by wizards and other magical people to defend themselves against spells cast by others. There are also spells that can make physical things happen in the real world, such enchanting animals or objects and then making them do other things. Just remember that almost all spells will require belief, dedication and practice, practice, practice!