It's not able to generate pressure to get the car started and maintained at idle, and so it starts up, and then the RPMs drop until it just shuts off. Once you get driving, you don't need that much pressure anymore and so that's why you can drive normally, but it has a hard time starting up.
Run BG-12 Chemtool through your fuel (to possibly unclog your fuel pump if that's the problem). If after 20 miles of driving with that in your gas tank you still have the problem, you need a new fuel pump.
You can get a fuel pressure test from any mechanic for $20, so you can also just go straight to that. It will tell you 100% if the problem is a bad pump or not.
Chat with our AI personalities