I think that you should not escape queries with the help of preg_replace. Not only do you have to detect when you have multiple conditions in your where statement, but you have to worry about quotes inside each value. Let's say your $where var is something like this:
PHP Code:
$where = "article = '$value'";
If $value somehow manages to be something like ' OR '1'='1, (see SQL injection) then your $where variable will contain this:
PHP Code:
"article = '' OR '1'='1'"
I don't think there's anyway you can properly sanitize that with the method you are currently using, nor with the method you want to use.
I think a much safer way is to use mysql_real_escape_string individually on every single variable you put in a query.
PHP Code:
$where = "article = '".mysql_real_escape_string($value)."'";
This prevents sql errors and sql injection, and even though it may make your PHP code around queries look longer (and possibly more complex) it's a very good habit to follow imho.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
|