Quicksand is a dangerous thing to walk into. Consisting of a mixture of sand and water (and sometimes clay and silt), anyone stepping into it will find themselves sinking. The vacuum produced when the sand surrounds your leg makes it difficult to pull out and there may be a tendency to panic.
Don't panic. Thrashing or freaking out is the number one way to squeeze sand and air away from your legs and make yourself sink quicker. The number 1 rule of landing in quicksand: STAY CALM.
Stay calm. Don't thrash. Call for help.
Second, get rid of anything you're wearing that is heavy, like a bag. The extra weight will cause you to sink and unless you've got a lasso or large hook to pull you out, ditch it.
Surprisingly, if you stay still and calm, you won't sink very far. It's the thrashing around that can make the situation deadly.
Standing still won't get you out though. There are some simple moves you can take to get yourself into a survivable position. Lean back, laying your upper body along the top of the sand. Quicksand is much more dense than water and you will float more easily. Once leaning back, SLOWLY bring your legs out of the quicksand, even part-way. Do everything in slow motion, as pulling hard can cause friction and more sinkage.
Once your legs are mostly out and you're floating, use your hands to gently stroke your way along the surface of the quicksand. You can slowly paddle your way to solid ground. This could take hours and there is no rush. The calmer and slower you take it, the less likely you're going to sink.
If you can grasp solid land or a large stick, you may be able to get your shoes off (flat soles shoes can cause nasty suction). Use the stick to push your shoes off (don't put your hands under the sand!). If you don't have a stick, but have a grasp on some solid object, gently spin your legs in 360 degree circles while pulling up to loosen the sediment. This will open up the suction and let you get your legs out.
Here are some professionals that deal with quicksand removal for a living, simulating a rescue