Messing up on messing on? If you dog is tearing up your carpets that is a sign of pent up energy. In that case you need to exercise your dog more. Make time in the morning for at least a 1/2 an hour walk and another hour or so later in the day. If you don't have time, hire a dog walker, or use a doggie day care a couple of times a week.
If it messes on, have you dog checked for a medical issue. If there isn't one get back to house breaking 101. Get your dog on a potty schedule. When they get up, and after eating are a must for going outside. Depending on the age your dog will need to go out anywhere from once an hour for a puppy to no more then every 8 hours as an adult. Again exercise is a good thing.
Take him out more outside or if you use puppy pads , but him on the pad and don't let him leave till he does his job and reward him for it if that doesn't work then get a spray bottle and spray the puppy every time he does it on the rug he or she will catch on :)