This is probably caused by a faulty charging port, when you replace it put a original charching port in from a other iphone same type.
open