-1

有人可以帮忙吗,我想在数据库中插入一些带有换行符的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');
4

2 回答 2

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

于 2013-03-25T03:56:46.543 回答
-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');
于 2013-03-25T03:51:44.723 回答