My car keeps shutting off while I'm driving and I am able to turn it back on... on 1999 BMW 323i

but it happens every day at least four times. What could be wrong?

Asked by for the 1999 BMW 323i
Common cause for such a condition is the crankshaft position sensor.
yes it was that, I changed it and is working much better now, but now another thing came up...for some reason everytime I stop the car it starts shaking a lot =(
1 more answer , 1 more comment
I can't speak for a 99 BMW, but I have experienced something similar on my 1998 Honda Accord. The Honda dealer believes it is a problem with the ignition switch. It may be worn and telling the car it has been shut off, even if you don't touch the key. I also had problems starting the car. He suggested that once I turn it to the start position and then release it slowly, not letting it "snap" back to the run condition. This has temporarily addressed my problem until I can get the car in and have the switch replaced.
That's what I thought it was in the begining but it turned out to be the crankshaft sensor... thanks