2013-03-25 84 views
-1

有人可以幫忙,我想換行到數據庫中的值插入一些HTML文本,但是當我在行添加打破它會導致查詢失敗,我認爲這是監守mysql的犯規支持HTML換行符
將html內容作爲值插入到mysql數據庫中?

可有人告訴我一個辦法可以讓我的換行文本結構和得到查詢工作的感謝。

多數民衆贊成給我的麻煩值是「內容」。

$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 [email protected]<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'); 
+0

因爲你不逃避它失敗字符串內的單引號。 – Tchoupi 2013-03-25 03:50:53

+0

那麼我該怎麼做? – 2013-03-25 03:53:59

回答

-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 [email protected]<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'); 
+0

當我嘗試這個 – 2013-03-25 03:56:11

+0

對不起只是尚未完成編輯,這只是帶來了syntaxt錯誤。 – 2013-03-25 04:00:37

+0

它解決了你的問題嗎? – 2013-03-25 04:28:48

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 [email protected]<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);

你現在可以在INSERT語句中使用$res的價值,爲content