My iphone only charges sometimes?

When i plug in my iphone 4 charger it has a yellow triangle and says that charging is not supported. I have tried all kinds of chargers and cleaned the charging port but nothing works. However, i found that if i plug it in my phone about 20 times i get lucky and it works. What could be wrong with it and how do i fix it? All advice is greatly appreciated!

While it says "charging is not supported" its still charging. Mine does this too. Turn on the battery percent (settings, General, usage, battery percent" and leave it plugged in for about 20 mins and the number will rise.

Happens on many phones. Its annoying on the iPhone 3gs ( I have now upgraded.)