How can I fix iTunes to sync apps and musics?
As @patrix said, check the Apple ID under Settings > iTunes and App Store on your phone. Also, make sure you DELETED the app your friend bought with their Apple ID before you try syncing to your iTunes on your computer.

Goes without saying, make sure your same Apple ID is used on your iTunes on your computer.