Well it could be several different things some of which might include a faulty drivers door latch, corrosion in any of the door pillar connectors, faulty module etc etc. I think if I were you I would take it back to where I bought it and tell them that this is a safety issue and that you are afraid you or a family member may either be locked outside of or even worse INSIDE of the vehicle. Ask them to fix it or have it fixed for you. If the bought the vehicle private party then you may be stuck taking it to a BMW dealer and paying for the repairs, or trying to get the seller to participate in the payment. Regardless, it sounds as it is going to be necessary to have a qualified repair shop diagnose and repair the problem.