Data Cleaning Function


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ################################################################
  2. #
  3. # Data Cleaning Function
  4. # - helps prevent MySQL injection, use when building the query after database connecton established
  5. # - Original Source: http://www.digital-web.com/articles/bulletproof_contact_form_with_php/
  6. # - trim function added by me
  7. #
  8. ################################################################
  9. function cleanData($string)
  10. {
  11. {
  12. // strip slashes if mahic quotes are on
  13. $string = stripslashes($string);
  14. }
  15. // remove unwanted HTML (not allowed)
  16. $string = strip_tags($string);
  17. // trim any leading and trailing whitespace
  18. $string = trim($string);
  19. // return the string with escaping slashes
  20. return mysql_real_escape_string($string);
  21. }

URL: php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.