The reason can be because of a faulty charging connector. Before trying the solution mentioned here make sure that you are not using the same data cablel with both the charges you have tried.
if you have alcohol or nailpolish remover with you, wet the tip of a tooth brush and gently clean the charging port by holding the the phone perpendicular to the groung and charging port facing the ground. This is to make sure that the alcohol doesn't get inside the phone.. Then wait for the alcohol to dry and check wether the device is charging or not.
Please note that this is not a permanant solution. May be the charging port will work for a month or may be an year, I recomment ro replace the charging port at the earliest.