This is a common problem from which suffer some Motorola users :

This just started today. I plugged in my phone to charge and at first the red light would come on that it was charging but a few seconds after, it would turn off even though it was plugged in. I disconnected the charger and plugged it back in, rebooted the phone and still same problem. I managed to leave it still once and it actually charged but other times it says it's charging but the battery percentage keeps going lower. What is the deal here? I haven't dropped the phone or anything that could break it. It just happened.
Squeeze the shell (closed) on the charger end (male) plug just a bit. Now with a magnifying glass and a sewing needle gently and slighly pry up the 2 pairs of outer tensioning devices on that charger cable male plug to restore and even augment their original spring action.
Guarantee if your phone port is worn this will help noticeably if not fix it altogether for awhile. Then do it again as necessary.

(PS don't forget to clean the phone port contacts removing the battery first of course)

Now I can wiggle it around at will light stays on, and lights up first time every time when you plug it in.
--------------------
This has solved all my charging problems as you are also experiencing.

To the person who bought a battery and charger:
Can you charge the battery and use the phone and recharge it in your charger? If so it's probably still just a worn/dirty USB port.

Most electronics problems are like Occam's Razor and adding the word mechanical. The simplest mechanical variable possible is usually the source of the trouble. In this case it's the USB port.

Both the Female (phone) and Male (charger) side of this connection are experiencing wear. Thus from a troubleshooting point of view simply trying another (possibly worn) charger plug is bad logic, it may be worn too. Prying up the 4 springs (2 on each side) on the charger plug compensates for the wear on the phone plug, squeezing the plug shell ensures it has not expanded also (it's essentially a female inside of a male connector, the phone side a male inside a female)