If you do something 'for someone's sake' or 'on behalf of someone', you can use 给
[给 + noun] = [for + noun (for noun's sake)] e.g. 给我买东西 (buy thing for me = buy thing for my sake)
[给 + noun] = [for + noun (on behalf of noun)] e.g. 给我重重打 (severely beat someone for me = beat someone on my behalf). In this case, 给 is interchangeable with 替 (on behalf of)
If you do something 'for someone's sake', or 'because of someone' you can use 为
[为 + noun] = [for + noun (for noun's sake)] e.g. 为我买东西 (buy thing for me = buy thing for my sake)
[为 + noun] = [because + noun ] e.g. 为我而受苦 (suffering because of me)In. In this case, 为 is interchangeable with 因 (because of)