15 Dec
Mostly we used normal insert MySQL query, but in the same time if user inserted special characters then to prevent this we can use normal php function. Below is the example of function
// when inserting string into database
function F_SAFE_INSERT2( $string ){
if ( function_exists(‘mysql_real_escape_string’) ){
return mysql_real_escape_string( trim($string) ) ;
}elseif ( function_exists(‘mysql_escape_string’) ){
return mysql_escape_string( trim($string) ) ;
}
return addslashes( $string );
}
This function will add extra prams to prevent mysql query break.
you can use this with MySQL insert query like:-
$mysqlQuery = “INSERT INTO TABLENAME SET `name`= ‘”.F_SAFE_INSERT2($yourVaribale).”‘”;
$mysqlQueryRun = mysql_query($mysqlQuery);
I am a software engineer who specializes in Internet applications. I have worked with a wide variety of technologies and programming languages to open source LAMP environments. I have more than 6 years of object-oriented programming experience and am highly proficient in ActionScript, PHP, MYSQL, JavaScript, Jquery and a multitude of other technologies used in modern web applications.
Follow me
Latest posts by Rajeev Achra (see all)
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016