The problem could be anything, it could either be water damage or your charging pin could be damaged (Due to any physical or any other type of collision). or it could either be:
Charging Connector is water damaged
Dry solder of connector pin
Pins doesn’t make contact with board
Faulty components.
Anyways here is a blog that has explained this thing in a step by step manner, for you to know how can you overcome this issue, i hope it works for you.
http://blog.brokenlcds.com/iphone-4-charging-problem-solution/