What is the problem if a car starts and then turns off but if you unhook the negative terminal for the battery and hook it back up the car will start fine?

The a sensor is bad, removing the cable resets the ecm