0

我在使用 SQL 查询时遇到问题。SQL 语句已通过,mysqli_real_escape_string但我仍然收到 SQL 语法错误。该代码适用于 99.9% 的网站,但以下代码不起作用。这可能是非常简单的事情,但我无法发现它。任何帮助将不胜感激。

"UPDATE text_t SET copy=\'<table cellspacing=3>\r\n  <tr><td  class=\"infogrey\">Secretary</td><td class=\"infogrey\">Some Name</td><td class=\"infogrey\">Telephone: 01794 123456 <br><a href=\"contact.php?type=Contact_Secretary\" target=\"content\" class=\"infogrey\" onMouseOver=\"window.status=\'contact\'; return true\" onMouseOut=\"window.status=\'\'; return true\"><strong>Email Some Name</strong></a></td></tr>\r\n  <tr><td class=\"infogrey\">Chairman</td><td class=\"infogrey\">Some Name</td><td class=\"infogrey\"><a href=\"contact.php?type=Contact_Chairman\" target=\"content\" class=\"infogrey\" onMouseOver=\"window.status=\'contact\'; return true\" onMouseOut=\"window.status=\'\'; return true\"><strong>Email Some Name</strong></a></td></tr>\r\n\r\n  <tr><td class=\"infogrey\">Club Kit</td><td class=\"infogrey\">Some Name</td><td class=\"infogrey\"><a href=\"contact.php?type=Club_Kit\" target=\"content\" class=\"infogrey\" onMouseOver=\"window.status=\'contact\'; return true\" onMouseOut=\"window.status=\'\'; return true\"><strong>Email Some Name</strong></a></td></tr>\r\n\r\n  <tr><td colspan=2 class=\"infogrey\">For General queries </td> <td><a href=\"contact.php?type=General_Query\" target=\"content\" class=\"infogrey\" onMouseOver=\"window.status=\'contact\'; return true\" onMouseOut=\"window.status=\'\'; return true\"><b>Email Cycling Club</b></a></td></tr>\r\n  <tr><td colspan=2 class=\"infogrey\">Any membership queries </td><td><a href=\"contact.php?type=Contact_Editor\" target=\"content\" class=\"infogrey\" onMouseOver=\"window.status=\'contact\'; return true\" onMouseOut=\"window.status=\'\'; return true\"><strong>Email Some Name</strong></a></td></tr>\r\n 
... </table>\' WHERE id=8"
4

1 回答 1

1

由于您使用双引号"来包装查询字符串,因此不应转义'列副本中的两个单引号:

$query = "UPDATE text_t 
    SET copy='" . mysqli_real_escape_string($dblink, $string) . "' 
    WHERE id=8";

看起来您可能还想修改mysqli_real_escape_string PHP 函数以及 PHP中单引号和双引号之间的区别:)

于 2013-07-12T11:10:25.940 回答