This is probably the question most asked by those who are new to fermenting or who are “fermenting-curious”.
While I am not a scientist or medical professional, I can only impart what I have learned, as well as what others before me have done in the thousands of years since fermentation began as a preservation method.
Fermentation is a biological, highly complex process involving many symbiotic species of critters. One group “passes the baton” to another as the pH of the brine lowers (becomes more acidic, preserving the contents).
If you are fermenting vegetables in a container that’s open to the air (i.e. if you’re not using an airlock or a Harsch crock), then the formation of mold (usually white colored) on the surface is normal. Aerobic critters (molds) form on the surface of the brine, but they do not affect the contents below the brine, which are dominated by helpful lactic acid bacteria. Simply do your best to wipe any mold away. As an extra precaution, you may wish to stir the entire contents, which will churn any residual mold into the contents (and promptly kill it due to the acidity). If you do this, remember to smooth out the surface of the contents before replacing the weight, or ensure that all contents are submerged.
What about botulism? Here’s a great explanation from Sandor Katz on why the risk of botulism when fermenting (as opposed to canning) is nil.
With solid technique and preparation, your ferments should be fine. That said, Life is fraught with risk. On occasion, things will go astray (I’ve had several ferments that were “off”). The best advice (not that I’m doling it out) is to Trust your Senses. If it looks, smells, or tastes off (yes, even “ruined” batches won’t kill you if you take a small bite), throw it out.