My iPhone has been erratically charging for a couple of weeks. It kinda sneaks up that it isn't charging when I've had a couple of days where it has been down to the red battery level unexpectedly.
I checked the various charging cables and noticed they needed to be wiggled before the phone would charge. Then I remembered the occasional need to blow into the lightening port. This time no difference and I couldn't find the canned air to give more of a blast. Instead I found a small screwdriver to pick carefully at the lint which had worked its way into the slot. A surprising amount, easily enough to stop electrical connections. Of course, if I were telling someone else to try this I'd suggest using a non conductive material such as a toothpick.
Normal charging (including through a charging dock) has resumed.