Sounds like a bad power cord/cable.
If it is a laptop it could also be an internal broken power connector.
Take out the battery, try wiggling the power plug, watch the AC power indicator light see if it's flashes while wiggling the plug.
Where the adapter plugs into the laptop can take a lot of strain. This is a common problem with certain model notebooks. I worked at a repair depot and on one specific model of Sony, 99% of the repairs for that model were new power plugs on the motherboard.