Php function to prevent SQL injection.
I am developing a Wordpress project wich I require users to insert some data of their need. I have created new tables in database for my use, though, now I need to be safe and protect from SQL injection.
For this use I have created following var.
function sql_escape($var){
if(is_string($var)) {
$result = strip_tags(addslashes(str_replace(array('SELECT', 'select', 'DELETE', 'delete', 'INSERT', 'insert', 'JOIN', 'join', 'CREATE', 'create', 'UPDATE', 'update', 'FROM', 'from', 'WHERE', 'where', '*', '=', '+', '-', '<', '>'), '...', $var)));
return $result;
}
if( is_numeric($var) || is_float($var) ){
$result = $var;
return $result;
}}
Do you think this could be enough ? Thanks everyone for support.