Recently somehow our son's cot was broken and I had to take out the frame to see and it had loose slats and other parts coming off.
How can I keep the slats in the side beams and make sure they are tight?
You can see that the slats have glue on the ends. It was applied sloppily and the bonds let go. Get some good wood glue (Titebond, etc.) and use a cotton swab or similar to coat the entire inside of each slat socket in the rails. Also coat the slat ends lightly.
Assemble the railing (one or more helpers make this easier) and use rope or elastic straps to keep it together while the glue dries. Be sure that the rails are the correct distance apart to mate with other parts of the bed.
Use a damp cloth to wipe away any glue that squeezed out. Allow 24 hours for drying and reassemble the bed. Check occasionally for more leaking glue.