Zippers can come undone for a number of reasons. There are plenty of ways to repair this. One way to improve the overall operation of a zipper is by lubricating it with the graphite from a pencil. That can stop the zipper from getting stuck, which in turn can prevent forcing the zipper. Forcing the zipper is what usually causes the zipper to become damaged and start separating.
The first step to repairing your zipper is making sure you have all the required tools. The consequence of not doing this could be getting halfway through the job only to find out you don't have sewing supplies and risk damaging the zipper more. The tools you need are pliers to adjust any of the zipper parts, scissors to potentially cut some of the surrounding fabric, and a needle and thread to repair any cuts.
Remove the Stopper
A separating zipper can be caused by misalignment. The first step in fixing this is taking off the stopper. This is the metal piece at the bottom of the zipper that stops you from taking the slider off every time you unzip. Once you've realigned your zipper you can make a new stopper by sewing one on.
The next step is to realign the zipper. Simply make sure that the two sides of the zip are meeting properly and that there are no teeth without mates. This is what causes a zipper to separate as the way a zipper works is by all the teeth holding each other together. A lone tooth means that the next tooth is not being held in and it may come loose.
You may need to adjust this several times to make sure that everything is aligned properly. You may need to replace the zipper altogether. This is especially true if one of the teeth is broken. This cannot be repaired except by replacing the zipper. Bent teeth on the other hand are easy to repair by simply bending them back into position with pliers of a pin.
Tightening the Base
One common cause of a separating zipper is that the stopper is too loose. This causes the bottom to slip out of the base and leads to the zipper separating from the bottom. The solution is to tighten the base using pliers. It's important to do it in stages to prevent it from becoming too tight. Tighten slightly, and then try the zipper. If it still slips out of the base, tighten it slightly and try again.