I'm having problems inserting records into an MSSQL database if the field has an apostrophe in it. For example 'It's'. I've tried the addslashes function with no help. I don't really want to store in the database a slash in front of each apostrophe, but I will if it's the only option. Any help on these inserts would be tremendously appreciated!!
Well, I suppose you could
str_replace("'", "''", $variablename);
and insert $variablename into sql.
SurgeProto wrote:I'm having problems inserting records into an MSSQL database if the field has an apostrophe in it. For example 'It's'. I've tried the addslashes function with no help. I don't really want to store in the database a slash in front of each apostrophe, but I will if it's the only option. Any help on these inserts would be tremendously appreciated!!
here is a quote from the manual you may find helpful -- in response to addslashes():
PHP Manual wrote: Note, this function wont work with mssql or access queries. Use the function above (work with arrays too). function addslashes_mssql($str){ if (is_array($str)) { foreach($str AS $id => $value) { $str[$id] = addslashes_mssql($value); } } else { $str = str_replace("'", "''", $str); } return $str; } function stripslashes_mssql($str){ if (is_array($str)) { foreach($str AS $id => $value) { $str[$id] = stripslashes_mssql($value); } } else { $str = str_replace("''", "'", $str); } return $str; }
Note, this function wont work with mssql or access queries. Use the function above (work with arrays too).
function addslashes_mssql($str){ if (is_array($str)) { foreach($str AS $id => $value) { $str[$id] = addslashes_mssql($value); } } else { $str = str_replace("'", "''", $str); } return $str; } function stripslashes_mssql($str){ if (is_array($str)) { foreach($str AS $id => $value) { $str[$id] = stripslashes_mssql($value); } } else { $str = str_replace("''", "'", $str); } return $str; }