Make sure there is nothing in the charging port on the iPhone that may be hindering contact. You can use a small plastic or wooden toothpick to gently dislodge anything that may be stuck in the port.
Otherwise, if the iPhone is still under warranty, and the problem is determined to not be caused by normal use, or user damage, its possible repair can be free.
If its determined to be user damage, or other external factor, Apple may charge you an out of warranty repair fee. Look in the following link for pricing and details:
iPhone Service Pricing - Apple Support