Posted By

the_dev on 07/07/09


Tagged

mysql php array protection


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
pster
aleksanderek


Clean array for Posting / SQL injection protection


 / Published in: PHP
 

Need a function to clean your POST array before inserting into a database? Just pass $POST to this function.

  1. function clean_array_for_post($post) {
  2. foreach($post as $key => $value) {
  3. // stripslashes, we don't want to rely on magic quotes
  4. $post[$key] = stripslashes($value);
  5. }
  6. // quote if not a number
  7. if(!is_numeric($value)) {
  8. $post[$key] = mysql_real_escape_string($value);
  9. }
  10. }
  11. return $post;
  12. }

Report this snippet  

You need to login to post a comment.