Preventing SQL injection in Webapplication

By | December 13, 2013

You can handle all escape characters smartly in scripting languages like PERL and PHP.

The MySql extension for PHP provides the function mysql_real_escape_string() to escape input characters that are special to MySQL.

Below are the one example for esacpe input characters.

if(get_magic_quotes_gpc())
{
$name=stripslashes($name);
}
$name=mysql_real_escape_string($name);
$qry=”Select * from users where name='{$name}'”;
mysql_query($qry);

mysql_real_escape_string -Escapes special characters in a string fo use in SQL Statement.

Other escape characters methods are below

1) addslashes()-Quote string with slashes
2)stripslashes-Un-quotes a quoted string
3)get_magic_quotes_runtime()-Gets the current active configuration setting of magic_quotes_runtime
4)ini_get-Gets the value of a configuration option