How can you prevent SQL injection attacks when validating user input in PHP?