Re: Single quotes in INSERT statements?
| From: | dpgirago at mdanderson dot org | Date: | Tue, 25 Apr 2006 18:16:00 +0000 |
| Subject: | Re: Single quotes in INSERT statements? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-41741@lists.php.net to get a copy of this message | ||
Skip Evens wrote:
> Hello all,
>
> I'm brand spanking new to the list and have a
> quick question.
>
> I was under the impression that addslashes() would
> handle single quote marks in INSERT statements,
> but when I execute the following:
>
> $sql="UPDATE images SET orderno=$orderno,
> url='".addslashes($url)."',
> banner=$banner,caption='".addslashes($caption)."'
> WHERE imageID=$imageID";
>
> ...and $caption contains something like:
>
> "Don't look"
>
> ...the data is chopped off at the single quote mark.
>
> How, if not addslashes(), does one handle this?
Skip,
If you're using MySQl, try mysql_escape_string(), or
mysql_real_escape_string.
If using some other RDBMS, look for similar functions in their respective
manual(s).
You might also investigate the setting of the magic_quotes directive in
php.ini, or use
get_magic_quotes_gpc to return this value programmatically.
Hope this helps.
David