I dont know how but i somehow dropped my guitar (epiphone les paul) and the tuning peg cracked and later fell off. Can yiu buy replacement tuning pegs. If you can, how do you attach them to your guitar?

Yes you can buy replacement machine heads.
they come in 6. you have to remove the string, then unscrew them and screw the new ones on. then put a new string on. its quite simple.
Actually you can also buy them singularly, one of my tuning pegs bent and I was able to buy one on it's own. Although I got it from a small privately owned guitar/repair shop, so you may not be able to get single ones in bigger widespread shops.
Funny words.
One broke on my Maton MS and I got a replacement and had it put on at the shop for like 2 bucks. Piece of cake.