If you can spin the pedals, but the back wheel isn't moving, and the chain is all on correctly, then this means that the ratchet mechanism that allows you to freewheel is probably broken.
The action of freewheeling is when your bike is moving along but you don't have to spin the pedals.
There are two very different types of ratchet mechanisms on a bicycle.
There is a thread-on freewheel where the ratchet mechanism is within the sprockets.
There is also the more modern freehub and cassette where the ratchet mechanism is within the freehub body.
On my bike
I have a freehub so I need to replace it to fix the problem. If you have a thread-on freewheel you just need to replace the freewheel unit.
(Second photograph stolen from sheldonbrown.com
- excellent resource for bike mechanics.)