Is this a safe way to filter data and prevent SQL-injection and other attacks?
I created two simple functions to filter inserted data before it's entered into a mysql query. For formfields (I am also using regular expressions to check each field individually. // Form filter function filter($var) { // HTML is not allowed $var = strip_tags(trim($var)); // Check magic quotes and stripslashes if(get_magic_quotes_gpc()) { $var = stripslashes($var); } // Not using it right now, is it recommended? // $var = htmlentities($var, ENT_QUOTES); // Escape $var = mysql_real_escape_string($var); // Return return $var; } Then for id's (sent in the URL) I am using this filter: // ID