作者CindyLinz (Cindy Wang)
看板PHP
标题Re: [请益] 无法INSERT有西欧字母的资料
时间Sun Jul 3 22:18:21 2011
※ 引述《asdd (我爱胖颖颖)》之铭言:
: 当我在执行INSERT的时候 某些资料有西欧字母 确有错误讯息
: 1064: You have an error in your SQL syntax; check the manual that corresponds
: to your MySQL server version for the right syntax to use near 'Association
: francaise d'urologie et de la Societe francaise d'urologie','[Manage' at line
: 1
: 请问该怎样解决这样的问题呢?
: 另外当有多笔资料要INSERT,如果像上述情况无法INSERT的时候有没有办法让他
: 自动忽略继续执行其他资料的INSERT呢, 我查到的资料是写
: 原本INSERT INTO 改成 INSERT ignore INTO就行了
: 不知道还有没有其他方法呢?
: 谢谢
应该是因为你用单引号来写 SQL 的字串, 而你的内容里面又出现了单引号的关系,
你可以利用 mysql_real_escape_string 来解决 (假设你是用 MySQL)
http://php.net/manual/en/function.mysql-real-escape-string.php
mysql_query("insert into .... values ('".mysql_real_escape_string($data)."', ...");
这样子~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.242.246.249
1F:推 asdd:谢谢 已解决 果真是这样子!! 07/03 23:18
※ 编辑: CindyLinz 来自: 210.242.246.249 (09/10 13:15)