RE: [PHP-DB] MySQL query failing on apostrophe in data
| From: | Jennifer Goodie | Date: | Wed, 27 Aug 2003 19:40:56 +0000 |
| Subject: | RE: [PHP-DB] MySQL query failing on apostrophe in data | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-30143@lists.php.net to get a copy of this message | ||
> How do I avoid the problem in the subject hereto? SELECT query uses
> variable in the WHERE clause. Fails on the following query:
>
> SELECT Tbl.fld FROM Tbl WHERE Tbl.fld2='11301201 0603A HKA 3902 #3708_JD's
> AE Exp' AND ...
Escape it.
SELECT Tbl.fld FROM Tbl WHERE Tbl.fld2='11301201 0603A HKA 3902 #3708_JD\'s
AE Exp' AND ...
Use mysql_escape_string() or addslashes()
http://www.php.net/manual/en/function.mysql-escape-string.php
http://www.php.net/manual/en/function.addslashes.php