Chosen Solution
My macbook started displaying the folder with the question mark. I tried replacing the hard drive, then the hard drive cable, and neither worked, although it works fine with the old hard drive in an enclosure. What else could be the problem?
Given the fact your system is working using an external drive we know the problem is focused around the internal drives logic and the physical pathway. Did your system get wet? Do you see any corrosion on the logic board around the HD ribbon connector? Often when you get to this point either the ribbon cable connector is damaged its self on the logic board or the logic board has some liquid damage around the connector. Use a soft toothbrush with some Isopropyl alcohol and carefully clean the solder connections of the connector. Don’t flood the area to much as you don’t want to get everything wet. Then using a cotton swab (Q-Tip) wipe up the alcohol and give it a try again. Did yo damage the ribbon cable or the connector? You may need to get another cable if the connector is damaged then thats something someone with SMT soldering skills will need to deal with as thats not simple to fix without the special tools and skills.