The first indication that my iPhone 5 had a problem was during a car trip. I had plugged the iPhone into the charger while using it for battery-sucking GPS navigation, but it still ran out of power and shut down. Fiddling with the cable restored the connection, and the iPhone booted back up and charged fine. Every so often after that, when I plugged the iPhone into a Lightning cable — and it didn’t matter which one — there wouldn’t be a connection, and the iPhone wouldn’t report that it was charging. That it happened at all was concerning enough, but the problem got worse. For the last several weeks, I’ve had to apply firm upward pressure on the Lightning cable to make a connection, and the last few nights, I had to stack books on the iPhone to maintain the necessary pressure.
Needless to say, I was worried, since the iPhone 5 is well out of warranty and I don’t want to have to buy a new one. The charging problem had all the indications of some solder joint or internal wire slowly breaking, and the amount of force I had to apply to the Lightning cable felt like it might cause damage on its own.
I was preparing myself for what looked like — thanks as always to iFixit — and perhaps $40–$50 in parts and tools, when I did just a bit more research. That’s when I came across  suggesting that the problem might in fact just be lint or other crud in the Lightning port. Given that my iPhone lives in my pocket all day long, it would be entirely understandable if a little fuzz had worked its way in there.
No crud was visible in the Lightning port, and a quick blast with a can of compressed air didn’t blow out anything I could see, but even so, it solved the problem. Since I cleaned out the port, the iPhone charges properly with any Lightning cable, and with no pressure necessary. Others have reported using a paperclip or pin to clean out the Lightning port, but the compressed air approach seems safer.
I won’t pretend that pocket lint is the only possible reason an iPhone might not charge, and if you’re experiencing a similar problem, make sure you eliminate all the variables. A particular Lightning cable might be bad (particularly if it’s not an Apple-branded cable), a USB port or wall charger might have failed, or you might even have a flipped circuit breaker to a particular outlet. (I once thought an electric toothbrush had died because it wasn’t charging, and it took quite some time before I realized that particular circuit’s breaker had flipped, since nothing else was plugged into it. Doh!)
And, of course, it’s entirely possible that my initial worry about the Lightning port connection failing could be true for you, at which point iFixit’s teardown might be necessary. on the Apple Support Communities runs through all of these possibilities and more, so if my suggestions don’t help, browse through all 18 pages of replies to see if anything else sounds worth trying.