将html内容作为值插入mysql数据库?

时间:2013-03-25 03:48:25

标签: php html mysql

有人可以帮助,我想将一些带有LINE BREAKS的html文本作为值插入到数据库中,但是当我添加换行符时会导致查询失败,我认为这是因为mysql不支持html行休息

有人可以告诉我一种方法,我可以使用换行符保持我的文本结构,并让查询工作,谢谢。

给我带来麻烦的价值是'内容'。

$query="INSERT INTO ptb_messages (id,
from_user_id, to_user_id, subject, content)
VALUES('NULL',
'1',
'".$_SESSION['user_id']."',
'Welcome...',
'Hi There :D,<br/><br/>
Welcome to your brand new, sparkling profile. We're so excited to have you with us! We just wanted to check in on you to see how you were getting on, and to let you know that if you have any questions or comments for us then please do not hesitate to get in touch at Support@fixstructure.com.<br/><br/>
fixstructure.com is a fun, friendly and clean community, please help us keep it this way. We want you to enjoy your new profile to the maximum but there are a few do's and dont's, for more information checkout our Terms and User Policy under the help link in your Account Settings menu.<br/><br/>
That's pretty much everything, so thanks once again for joining the fixstructure.com community and we look forward to seeing more of you and watching your new profile grow in the future.<br/><br/>Regards,<br/>The fixstructure Team'
)";
mysql_query($query) or die('error');

2 个答案:

答案 0 :(得分:0)

将您的内容添加到变量中,例如

$content = "Hi There :D,<br/><br/> Welcome to your brand new, sparkling profile. We\'re so excited to have you with us! We just wanted to check in on you to see how you were getting on, and to let you know that if you have any questions or comments for us then please do not hesitate to get in touch at Support@fixstructure.com.<br/><br/> fixstructure.com is a fun, friendly and clean community, please help us keep it this way. We want you to enjoy your new profile to the maximum but there are a few do\'s and dont's, for more information checkout our Terms and User Policy under the help link in your Account Settings menu.<br/><br/> That\'s pretty much everything, so thanks once again for joining the fixstructure.com community and we look forward to seeing more of you and watching your new profile grow in the future.<br/><br/>Regards,<br/>The fixstructure Team";

然后致电

$res=addslashes($content);

您现在可以使用$res作为content列的插入语句中的值

答案 1 :(得分:-1)

逃离单行情..   并且还会使用""''

    $query='INSERT INTO ptb_messages (id,
from_user_id, to_user_id, subject, content)
VALUES("NULL",
"1",
"'.$_SESSION['user_id'].'",
"Welcome...",
"Hi There :D,<br/><br/>
Welcome to your brand new, sparkling profile. We\'re so excited to have you with us! We just wanted to check in on you to see how you were getting on, and to let you know that if you have any questions or comments for us then please do not hesitate to get in touch at Support@fixstructure.com.<br/><br/>
fixstructure.com is a fun, friendly and clean community, please help us keep it this way. We want you to enjoy your new profile to the maximum but there are a few do\'s and dont\'s, for more information checkout our Terms and User Policy under the help link in your Account Settings menu.<br/><br/>
That\'s pretty much everything, so thanks once again for joining the fixstructure.com community and we look forward to seeing more of you and watching your new profile grow in the future.<br/><br/>Regards,<br/>The fixstructure Team"
)';
mysql_query($query) or die('error');