There are several reasons why a car might stall when it is shifted into gear. The engine needs a specific amount of fuel and air when it idles and putting the car into gear puts pressure on the engine. This can cause a malfunction to cause a stall.
The idle air control valve disperses air into the engine when it is idling. Sometimes when the valve isn't functioning properly or is dirty, the air flow into the engine is jeopardised and won't allow the vehicle to run in gear.
Sensors tell the engine how much air is going through the engine. Dirty or failing sensors will send the computer wrong information and this can result in stalling.
The brake lights may draw too much on the alternator and cause the car to stall. This is usually a sign of the voltage regulator, faulty alternator or a short in the brake wiring.