I hadn't remembered buying his gift last week and bought another one this afternoon. This means you could not remember buying the gift but suggest you had bought it. However you have now bought a second gift. I didn't remember having bought his gift last week and bought another one this afternoon. Is not correct. More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.