Saruth,
First, let me correct the attempt at the Nokia 5310. T-mobile Nokias happen to be one of those phones that people in the unlocking industry do not like to unlock. The reason being is the turnaround time and the cost of it. If you hadn't ported your number and you were a T-mobile customer for I believe 6 months with some other criteria that had to be fulfilled, they would have given it to you for free.
Now that you're kind of stuck in this situation, your only hope is to purchase it from a third party unlocking company. If you have attempted unlocking this phone more than 4 times, then you've permanently bricked your phone from unlocking. Of course there are flashing solutions for that, but that's for another day.
The code that the above member had given may be correct. Rather than putting a +1 at the end, you may want to try a +2. The last Nokia 5300 that I unlocked didn't work with a +1, but worked with a +2. Nokias are kind of tricky that way.
As for your G1, it's basically the same process. Even if you had remained with T-mobile, they wouldn't have the unlock code because it comes straight from the worldwide HTC servers (overseas). Again, that would have to be purchased from a third party site.
I hope that answers your questions.