That's housetraining not obedience training. Take him outside after eating, after playing, and just regularly every few hours (and yes, that means during the night too for a few weeks depending on how old he is).

Whenever he squats to do his business, immediately praise him NEVER punish him for mistakes made inside the house (almost always those are the fault of the owner not the puppy).

If you can catch him just as he goes into squat mode in the house wisk him outside.

Try to connect the deed with a key word - mine was hurry up (because I did house training in December/January in Canada) because I wanted back inside (especially at 3 in the morning). But make sure he has enough time to do what he has to do - often WE are so impatient we bring the poor consequences on ourselves.

Consult your vet - they may be able to add to the above. Crate training (google if you need to) is a help, BUT it doesn't remove the necessity of taking puppy outside at regular intervals and after meals and after playtime.

Remember to not associate negativity with the process - you will live to regret it - celebrate the successes exuberantly - puppy WILL learn, just as you did.