SQL插入错误

时间:2014-09-26 14:38:02

标签: php mysql sql wordpress

我正在尝试对表运行插入,但是我的语句一直出错,因为我正在使用喜欢和内部的单词。

如何将这些段落放入数据库?

INSERT INTO messages (message_title, message_content, from_user,
                      to_user, date, type, delivered, deleted)
VALUES('Dont forget to configure your profile!',
       'Welcome to the Club. The FIRST step to getting started is to set up your
        personal profile and your personal goals. You cant improve what you dont
        measure! Click on the following link and get your profile set up today.
        Set up my profile NOW. If you have any questions please be sure to contact
        our support team at info@support.com.',
       '1', '1', '2014-09-26', '0', '0', '0')

1 个答案:

答案 0 :(得分:0)

我在这里对你的架构做了一些假设但是即将结束,所以想发布这个以确定它是否有帮助:

http://sqlfiddle.com/#!2/a1471/2

create table messages (message_title varchar(500), message_content varchar(8000), from_user int, to_user int, date datetime, type int, delivered bit, deleted bit);

INSERT INTO messages (message_title, message_content, from_user, to_user, date, type, delivered, deleted) 
VALUES(
'Dont forget to configure your profile!', 
'Welcome to the Club. The FIRST step to getting started is to set up your personal profile and your personal goals. You cant improve what you dont measure! 
    Click on the following link and get your profile set up today. Set up my profile NOW
    If you have any questions please be sure to contact our support team at info@support.com.',
'1', 
'1', 
'2014-09-26', 
'0', 
0, 
0);

select * from messages

我在此假设您的已删除和已发送的列是位字段,当尝试使用' 1'而不是1,语句错误。正如您可以通过小提琴看到的那样,(仅略微)修改后的insert语句确实有效。所以希望这会帮助你!

此外,您的其他人假设是int列,您也不需要引号插入其中。