Sunday, February 21, 2010

PHP - Avoid Apostrophy Problem When inserting data to database

function escapeSingleQuotes($string){

//escapse single quotes

$singQuotePattern = "'";

$singQuoteReplace = "''";
return(stripslashes(eregi_replace($singQuotePattern, $singQuoteReplace, $string)));

}
$type = escapeSingleQuotes($_POST['type']);
$description = escapeSingleQuotes($_POST['description']);

No comments:

Post a Comment