RE: [PHP] php mysql apostrophe issue
| From: | John W. Holmes | Date: | Sun, 04 May 2003 15:34:33 +0000 |
| Subject: | RE: [PHP] php mysql apostrophe issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146357@lists.php.net to get a copy of this message | ||
> I know that in order to insert an apostrophe into a mysql database,
> instead of putting one apostrophe, you need to put double apostrophes.
> So to do this, I am using the command:
>
> $NewTitleBox=eregi_replace("'", "''", $TitleBox);
>
> but instead of replacing the apostrophe with a double apostrophe, it
> replaces it with this \''
You probably have magic_quotes_gpc enabled, which is adding the
backslash before the original single quote. Then your str_replace() is
duplicating the single quote.
For mysql, the single quote can be escaped with a backslash or another
single quote. So, since magic_quotes appears to be on, you do not need
to do anymore escaping of the text.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/