作者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)