Use mysql_real_escape_string()provides full protection for string values. The fact that the data cannot be %and _does not matter, they do not pose a security risk.
For int values, you need to either check if they are actually numbers, or enclose them in quotation marks:
$intValue = mysql_real_escape_string($_POST["intValue"]);
$query = mysql_query("INSERT INTO table SET intValue ='$intValue'");
mysql_real_escape_string() !
, @ . , , PDO. , mySQL, , SQL- .