#1064 - 您的SQL语法有错误;正确的语法在'block'附近使用?

时间:2013-03-20 22:16:03

标签: mysql

我需要有关此查询的帮助:

update ibf_posts
set post =
replace (post,
'<div><div style="background: #B7E5CE;border: 1px dotted #000; border-bottom: 0; border-left: 4px solid #429E6F; color: #000; font-weight: bold; font-size: 10px; margin: 8px auto 0 auto; padding: 3px;">SPOILER <a href="javascript:void(0);" onclick="javascript:if(parentNode.parentNode.getElementsByTagName('div')[1].style.display=='block'){parentNode.parentNode.getElementsByTagName('div')[1].style.display='none';this.innerHTML='--Click here to view--';}else {parentNode.parentNode.getElementsByTagName('div')[1].style.display='block';this.innerHTML='--Click here to hide--';}">--Click here to view--</a></div><div style="color: #000000; background: #FAFCFE; border: 1px dotted #000; border-left: 4px solid #429E6F; border-top: 0; padding: 4px; margin: 0 auto 8px auto;display:none;">',
'[spoiler]');

我收到此错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'block')
{parentNode.parentNode.getElementsByTagName('div')[1].style.display='none' at line 1

有任何线索吗?感谢

1 个答案:

答案 0 :(得分:0)

由于您使用'(单撇号/引号)插入字符串,因此您需要转义字符串内所有相同的外观。

update ibf_posts
set post =
replace (post,
'<div><div style="background: #B7E5CE;border: 1px dotted #000; border-bottom: 0; border-left: 4px solid #429E6F; color: #000; font-weight: bold; font-size: 10px; margin: 8px auto 0 auto; padding: 3px;">SPOILER <a href="javascript:void(0);" onclick="javascript:if(parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display==\'block\'){parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display=\'none\';this.innerHTML=\'--Click here to view--\';}else {parentNode.parentNode.getElementsByTagName(\'div\')[1].style.display='block';this.innerHTML=\'--Click here to hide--\';}">--Click here to view--</a></div><div style="color: #000000; background: #FAFCFE; border: 1px dotted #000; border-left: 4px solid #429E6F; border-top: 0; padding: 4px; margin: 0 auto 8px auto;display:none;">',
'[spoiler]');

通过在引号前加一个反斜杠(\)来完成转义。