I am getting a syntax error with the follow code snippet:
$handle = $table.'_'.$field;
if($queryType=='replace') {
$sql[$handle]['sql'] = 'UPDATE '.$table.' SET '.$field.' = replace(replace(replace('.$field.',\''0', ''), '1', ''), '2', '')';
} else {
$sql[$handle]['sql'] = 'SELECT * FROM '.$table.' WHERE '.$field.' REGEXP(\''.$search.'\')';
}
I am sure I have just forgot something small but I cant seem to find out what is causing the error.
Any help would be much appreciated.
Your syntax error comes from line 3 of the snippet you provided: the end of that line,
',\''0', ''), '1', ''), '2', '')';, is causing the problem because the single quotes that are supposed to be a part of your SQL statement aren’t escaped. Rather than escaping all of them, it’s much simpler to just use double quotes to contain that part instead, like this:",''0', ''), '1', ''), '2', '')";Also, your current code is highly susceptible to SQL injection.