I have the same problem. The following solution may apply; here is how to IDENTIFY the problem:
(1) Phone doesn't connect to desktop software through USB but will through BT (if setup)
(2) Phone doesn't charge whether USB-computer, USB-wall, USB-carcharger or does sometimes but you are not sure why it works sometimes but not all the time
(3) If you hold, lean, twist, or jiggle the plug at the phone, it may charge or the charge icon may show briefly
(Also) Plug is noticeably loose or comes out
if plug is torn loose, damaged, or comes all the way out, go to this site and follow along in kind http://computerguru365.blogspot.com/2006/02/diy-blackberry-usb-repair.html
If plug is simply intermittant: remove all power and the battery, open your phone, and carefully redo the solder joints of the plug. If you don't have a SMT (surface mount) rated soldering iron w/ tip, you can use the radio shack standard but be sure to only apply the hot tip in pulses (less than/up to 50% of time, less than 3sec each touch) so you don't heat damage the surrounding components.
Because the plug gets tugged to the sides causing the solder joints to crack (microscopically). At first I had to lean books against the plug but then that quit working as well.
This approach also worked on my laptop which quit charging when plug torque flexed the motherboard and cracked the solder at some surface components near the plug. I found out which components when the varying the force of my multimeter tip cause the component to show open and normal across the solder joint