Gluing the sole of your shoe back to the upper may seem easy enough, but there are a few tricks you'll need to employ to make sure your glue job holds up. Some shoe stores may offer to glue your shoe sole for your for a low fee, possibly even for free if you bought your shoes there.
Visit your local shoe store and search for a shoe repair kit. Kiwi makes a shoe repair patching kit which comes with adhesive. You may also want to try Shoe Goo or Gorilla Glue, as both will do the job well.
Clean the area between the shoe and the sole so it is free of dirt. Make sure the area is dry, otherwise the glue won't hold when you apply it.
Read all instructions on the adhesive before you use it, and only apply the recommended amount of glue. Cover the sole area and the upper part of the shoe. Don't over-glue, even if you think it might be necessary.
Allow glue to dry for about ten minutes, then press the sole and the upper tightly together. You may want to hold the two pieces of the shoe in place with a C clip until they dry, as they might start to pull apart.
Warm the glue with a hair dryer as it dries. This will help even the glue out beneath the sole, so you don't have any uncomfortable lumps to irritate you while you're walking.
Let the glue dry for a full twenty-four hours before you wear your shoes again. This will give it time to completely dry, and keep you from having to reglue.
Avoid using a hot glue gun, or super glue, as neither of these types of glue hold up well for shoe repair.