MySQL error when inserting data containing apostrophes (single quotes)?

前端 未结 10 1089
不知归路
不知归路 2020-11-30 13:59

When I an insert query contains a quote (e.g. Kellog\'s), it fails to insert a record.

ERROR MSG:

You have an error in your SQL s

10条回答
  •  日久生厌
    2020-11-30 14:26

    You need to escape the apostrophe (that is, tell SQL that the apostrophe is to be taken literally and not as the beginning or end of a string) using a \.

    Add a \ before the apostrophe in Kellogg's, giving you Kellogg\'s.

提交回复
热议问题