Guitar strings are connected to tuning pegs at the head stock of your guitar. By turning the tuning pegs, you adjust the pitch of a specific string. The strings of your guitar create constant tension on your tuning pegs and can sometimes loosen the screw that attaches the tuning peg to the guitar's head stock. A small Phillips-head screwdriver is used to tighten and secure the tuning pegs to prevent your guitar from slipping out of tune.
Turn the loose tuning peg counterclockwise to release the tension of the guitar string. Turn the peg using your fingers until the string straightens out and can be easily pulled through the hole on the peg.
Use a Phillips-head screwdriver to secure the tuning peg to the head stock. Turn the screw clockwise to tighten the tuning peg and secure in position.
Replace the old string with a new one specific to the tightened tuning peg. Slide the string though the bridge of your guitar and insert the end into the hole on the tuning peg. Place four fingers vertically between the string and the neck of your guitar. This will leave you with enough slack to tighten the string without breaking it. Turn the tuning peg clockwise with your fingers to tighten and tune the guitar string. Use a guitar tuner to tune the string to the desired pitch.
It is not required to change the string, but it is recommended since the string tension is what probably caused the tuning peg to come loose in the first place.