skmd
01-09-2008, 09:36 PM
Hi everybody
I want to write a function to protect me from sql injection, so I can call it in every $_GET .
my $_GET is always an integer number ,I started with this function :function valid_id($id){
if (preg_match ("/^([0-9]+)$/", $id)){
(int)intval($id);
htmlspecialchars($id);
mysql_real_escape_string($id);
return $id;
} else {
return '0';
}
}
But the problem is it doesnt scape single quotes and if I insert a word it shows normally, I want the function to remove any letter and prevent any sql injection
can anybody help me out to write this function??
I want to write a function to protect me from sql injection, so I can call it in every $_GET .
my $_GET is always an integer number ,I started with this function :function valid_id($id){
if (preg_match ("/^([0-9]+)$/", $id)){
(int)intval($id);
htmlspecialchars($id);
mysql_real_escape_string($id);
return $id;
} else {
return '0';
}
}
But the problem is it doesnt scape single quotes and if I insert a word it shows normally, I want the function to remove any letter and prevent any sql injection
can anybody help me out to write this function??