There is nothing that can stop users from accepting bad answers. They are free to accept the answer that helped them the most, even when the answer is suggesting a bad practice.
What can be done in those cases is really simple: If the answer is that bad, and suggests something that should not be done, it can be down-voted. Before doing that, I would leave a comment letting the user who answered know why that is a bad idea. If the user doesn't edit the answer, then it can be down-voted. The comment will let other users know why it is a bad idea to do what the answer is saying. I would avoid making a discussion in comments, if the user who wrote the answer doesn't agree with the answer being a bad suggestion.
Moderators don't have any way to change the accepted answer, and in very few cases they will delete an accepted answer. (They could, if the OP wrote an answer instead of updating the question, and accepted the answer to avoid the question is shown between the answered questions.)