Why not make things simple.
To begin with, why do you want to replace , commas with ,_ comma-space?? Not necessary in SQL, right?
Write the whole SQL statement with userinputs use of ' apostrofies.
These will have to be replaced with '' double-apostrofies.
Instead of ereg_replace all elements before use this function:
function strip_apos($q) {
$q = str_replace("'","''",$q);
$q = str_replace("(''","('",$q);
$q = str_replace("'')","')",$q);
$q = str_replace("'',","',",$q);
$q = str_replace(",''",",'",$q);
return $q;
}
$sql = "INSERT INTO table(name, address) VALUES('Peter'','Be'ngtsson')";
$sql = strip_apos($sql);
Returns $sql like this:
$sql = "INSERT INTO table(name, address) VALUES('Peter''','Be''ngtsson')";
Look closely at the function and understand what it does. Quite simple acctually.
Please report if I causes you an error.