【问题标题】:Why is MySQL inserting ' \\ ' before my links?为什么 MySQL 在我的链接前插入 ' \\ '?
【发布时间】:2014-06-25 15:43:23
【问题描述】:

当我使用 PHP 通过表单插入链接时,我的数据库会在链接之前放置反斜杠。我使用 tinyMCE。

例如,这是它在数据库中的样子:

(14, 'MULTIMÉDIA', 'multimdia', '<h2><strong>RISING HARMONY&nbsp;</strong></h2>\r\n<p><strong>ITT A ZENE VIL&Aacute;GA URALKODIK.</strong></p>\r\n<p><strong>KEDVENC&Eacute;T &Ouml;N IS MEGOSZTHATJA&nbsp;</strong><strong>AZ AL&Aacute;BBI C&Iacute;MEN:</strong></p>\r\n<p><strong><a href=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;mailto:personicum@gmail.com\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\">personicum@gmail.com</a> &nbsp;</strong></p>', '<p><iframe src=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;/www.youtube.com/embed/1ov6USLXwGA\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" width=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;270\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" height=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;152\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" frameborder=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;0\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" allowfullscreen=\\"allowfullscreen\\"></iframe>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<iframe src=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;/www.youtube.com/embed/bnv6dPQ5f88\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" width=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;263\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" height=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;150\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" frameborder=\\"\\\\&quot;\\\\\\\\&quot;\\\\\\\\\\\\\\\\&quot;0\\\\\\\\\\\\\\\\&quot;\\\\\\\\&quot;\\\\&quot;\\" allowfullscreen=\\"allowfullscreen\\"> )

这应该是一个 youtube 视频,通过 tinyMCE 插入。它对图像和任何类型的链接做同样的事情。那么,我的问题是,为什么会出现这些东西?

这是表格:

CREATE TABLE IF NOT EXISTS `blog_posts_seo` (
`postID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`postTitle` varchar(255) DEFAULT NULL,
`postSlug` varchar(255) DEFAULT NULL,
`postDesc` text,
`postCont` text,
`postDate` datetime DEFAULT NULL,
PRIMARY KEY (`postID`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

使用另一个表它工作正常,所以这意味着问题不在于我的 php,但如果需要,我会在这里复制它。这个问题是由什么引起的?在网站上有一个 404 错误而不是视频。

如果我通过 MySQL 手动插入它们,那么一切都很好,但如果我通过表单插入它,它看起来像这样。另外,如果我在另一个数据库中使用相同的 php,它工作正常。这是一个悖论,我没有经验。我找不到问题。

另外,在本地它工作正常,它显示如下:

<p><iframe src="//www.youtube.com/embed/Lcu8SdcsYnY" width="425" height="350"></iframe></p>

提前谢谢你。

【问题讨论】:

  • 您似乎有编码问题,如果您也有转义问题,我不会感到惊讶。阅读:The Great Escapism (Or: What You Need To Know To Work With Text Within Text)Handling Unicode Front To Back In A Web App
  • 谢谢,我会读进去的。但我认为它必须是别的东西。正如我所说,在另一张桌子上效果很好。一个结构几乎相同的表,基本上是这个的旧版本。网络服务器可以这样做吗?
  • 那不是 MySQL,我敢肯定,那是用 PHP 处理你的数据。
  • 如果我复制到这里,请您看一下我的 PHP 吗?虽然我不知道为什么它适用于其他表而不是这个。
  • src=\\"\\\\&amp;quot;\\\\\\\\&amp;quot;\\\\\\\\\\\\\\\\&amp;quot;...哇XD

标签: php html mysql database hyperlink


【解决方案1】:

您在输入上多次运行addslashes() 或其他转义函数。您可能还会有魔术引号。您应该将字符串保持为原始字符串,并仅在插入数据库之前对其进行转义。最好使用 PDO 的绑定参数。

【讨论】:

  • 我的php很简单,我不使用任何特殊功能。我忘了提到它在本地运行良好。只有在网络上才会这样显示。
  • 这将导致magic_quotes_gpc 在服务器上。你考虑到这一点吗?在此处查看如何禁用它:php.net/manual/en/security.magicquotes.disabling.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 2011-12-03
  • 2016-08-27
相关资源
最近更新 更多