How long does it take to house train a male maltese puppy?

My neutered male Maltese is a little of 6 mos old now. Just 10 minutes ago, he came in from outside and went upstairs with me. He urinated on my carpet! I don't understand this...earlier this evening he stood at the door looking at me to let him out. He went out and did his business and came right back to the door. What's going on?