After you put the tube in you should push the stem into the tire as far as you can, so the tube sits inside the tire, then let the valve relax out back and pump it up. It's possible that you've been leaving it pinched under the bead of the tire, which could lead to a flat.
It's also important to get the valve stem pointing straight out (toward the center of the wheel). If it's bent sideways it can tear the tube.