This very much depends on whether it is a USB type B or C connector.
If the charger is the older type B the connector it has 2 small pins that click into place within the phone port, these fail and the quickest fix would be to try another cable/purchase a new one. If this does not work then the port on the device is damaged which will need to be fixed. Unfortunately this types of port can be damaged easily depending on how you use them. (Using the device while on charge etc)
If it is a type C then for sure try a different cable, but it is more likely that the port is damaged and will need to be repaired. In my experience these ports are a lot more durable, however damage can still occur.