"sometimes it does. suppose if i run my pc for a while then i switch it
off then i switch it on again power comes up lights on but hdd spins but
pc doesnt boot."

That's one of the signs of BAD CAPS. When these get really bad, then it gets worse. Google BAD CAPS to learn what to look for and how some folk fix that.

Most of us will change the motherboard.