I try to extract some information from one table and insert it to another. I'm using the following function from https://php.net/mysql_real_escape_string to handle the escape characters.
<?php
function mysql_escape_mimic($inp) {
if(is_array($inp))
return array_map(__METHOD__, $inp);
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
}
return $inp;
}
?>
The string I deal with is in html form with double and single quotes like
<input type="radio" value="choice_3" checked="true"/> Eat pig's belly and swine's matrix
I have to use string concatenation to write queries because column names and table names are dynamic.
$query .= "'".mysql_escape_mimic($string)."', ";
I know there is some kind of syntax error but I don't know how to fix it. Can anyone help me with it? Thanks.