I use the first generation iphone. My warranty is up like two years ago and I have already jailbroken my phone. It was functioning just fine until one day suddenly my laptop stopped detecting my iphone. I reconnected the device to a PC and the same thing happened. I guess its my mistake that I ignored it!. Then one day while I was riding on my bike,to my absolute horror the phone suddenly slipped from my pants pocket and fell on the rough concrete. I ran and checked but except for a few scratches on the back, it looked just fine, it jus got switched off. I switched it back on and it was working just fine. A week went by while I ignored my phone's inability to connect to any PC whatsoever. It was then that the issue started, Now my phone is not charging at all!. Sometimes either through a stroke of luck or a vigorous shake from me, it resumes charging! Help me out Please!. What am I to do to get it back to normal?!
if you still have warranty on it :
I would suggest you restoring the iphone to factory settings and taking it to the nearest Apple store.
I believe there is a hardware issue (loose connection). Since it is a 3G iPhone (warranty may have expired unless you got AppleCare), it is not difficult to open up and see whats going on inside.
Hope it helps!
p.s : When you say 'stroke of luck', things get interesting. You may put your iPhone in Restore mode and then see if iTunes is recognizing it (if you at least have any charge, only then will it be possible to try this!).
Check the cable slot on the iPhone. Is there any pocket lint in there? Try cleaning it out with some compressed air or gently clean it using a toothpick. I had some very strategic lint block just the right pins to cause this issue on my iPhone. Best of luck.