mysql插入報錯問題

來源:互聯網
上載者:User
INSERT INTO `Sale_Order` (`id`,`number`,`order_id`, `order_status`, `buyer_name`, `buyer_email`, `buyer_phone_number
`, `total_price`, `currency`, `phone`, `postal_code`, `recipient_name`, `ship_address`, `ship_state`
, `city`, `country`, `account`, `lastup_date`, `payments_date`, `delivery_date`, `download_date`, `delivery_warehouse
`) VALUES (NULL,'1','249-4503994-1570232','2','杉本 圭\','jc3mwnzmvtcqgpg@marketplace.amazon.co.jp','','1000
.00','JPY','','225-0003','ロ?ソ\ンL たまプラ?ザ?南口','橫浜市青?區新石川3?15?2 ','神奈川?','--','JP','JP_John','','2015-03-27T20
:43:50+09:00','',NOW(),'FBA')

以上報錯
#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 'jc3mwnzmvtcqgpg@marketplace.amazon.co.jp','','1000 .00','JPY','','225-0003','ã?' at line 2


插入之前都轉了UTF-8的,請問這裡面,哪有問題??


回複討論(解決方案)

'杉本 圭\' 看到了麼,你的單撇號被轉義了。因此會報語法錯誤。
如果是外部插入的,那麼很可能是因為你根本沒有過濾和轉義得到的參數。

請問怎麼過濾掉這些導致插入失敗的字元啊?

可以在插入之前就是用函數進行轉義,有個php函數叫

addslashes()?

先用mysql_real_escape_string做一次轉義

$name = mysql_real_escape_string($name);$sqlstr = "insert into table(`name`) values('".$name."')";
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.