It can be 2 things as I can think of
Charging cable
Charging port
Have you try outher charging port yet? or if not try one. Then try to hard reset the iphone to see if is the software problem or not.
If that doesn't help, it might be your charging port, try to blow out the dust or clean it...