How to put my music on my itunes library from iphone?

I recently restored my computer and i had to download itunes again.obviously no music was in the library so i thought putting my iphone in the music would go to the library. There's still no music in the library and also i can't transfer new songs to my iphone from itunes. I was going to restore the phone but it says i have to purchase everything again

If the songs are still on your iPhone, you need to go iTunes to "Transfer Purchases" when you connect iPhone to iTunes, then the songs on iPhone will be transferred to your iTunes. Meawhile, the most easy way is use iMediago to transfer the music from iPhone to iTunes or computer if you are on a Windows computer.

So actually, you don't need to purchase them again.

You may take a look at this step by step guide, it's about how to transfer files from iPod touch and iPhone to computer iTunes, it supports Apps, Contacts, Songs, Videos, Photos, Playlist, Games, etc. Data files. Easy to understand and works pretty well for my iphone.
http://welcometojenelleshouse.xanga.com/766907341/ipodiphoneipad-to-computer-transfer-review/