Hi and Welcome. My Name is ***** ***** I look forward to assisting you today with your question.
There are several reasons for the problem, like
Issue with the charging cable/adapter
Issue with the software
Issue with the charging port of your iPhone
And an issue with the battery itself
We can do some basic troubleshooting steps that is possible. First connect the iPhone to your computer with the cable came with it for 20 minutes. Your computer will charge the iPhone. Then hold down the Power button and Home button on your iPhone for 20 seconds or until it shows Apple logo. This is a method to reset the software of your iPhone. If this is a software glitch, then this reset will work.
If that didn't work, then connect the iPhone to your computer with another cable or connect to power outlet with another cable and adapter. This will tell us if there is any issue with the cord or adapter.
If none of the above is not working, then this is an hardware issue which could be an issue with the port or battery. Unfortunately, this is something we can't fix online and in this case, you have to take it to the Apple Store to replace the battery or port. Battery replacement from Apple Store will cost about $79.
You can make appointment from here --> www.apple.com/retail/geniusbar/
Replacing the battery won't cause any loss of data. Not only that, all your data should be on iCloud and you can check it from www.icloud.com if needed.
let me know how it goes please.
If you have any questions or would like any additional information, please don't hesitate to ask. If you are not satisfied with the service I provided, please don't rate me bad or poor. You don't have to rate anything if you are not satisfied.