It could be one of three problems. The first being a dirty charging port, if that's the case try cleaning it out with canned air or something similar to make sure you will have a solid connection between the charger and the port. The second problem could be a loose connection of the charging port to the logic board, if that's the case check the connection at the logic board and ensure its properly connected and fastened down. Lastly, it could be a bad logic board in which case you would need to get a replacement.