The next time it does this, turn the ignition on so the dash lights come on. Step on the brake pedal and shift the transmission into neutral and then try starting the engine. If the engine starts, the problem is with the park/neutral safety switch.
Tester