Agreed with the above; first rule out what you can.
Is the cable the original iPhone cable? If not, retest with the iPhone’s original cable first.
Apple’s reliability and quality control for their original cable would have me first look at the charger, though if another charger does the same thing, I would then test another cable, and then as a last resort take the phone into an Apple store to troubleshoot.