【问题标题】:MySQL insert fails with '&' characterMySQL插入失败并带有'&'字符
【发布时间】:2012-05-24 23:02:15
【问题描述】:

我在我的数据库中插入一行包含文本。

如果包含“&”符号,则记录插入失败。

文本取自网页textarea,网页字符集为utf-8

我的数据库架构是 MyIsam 和排序规则 latin1_swedish_ci

> 和

谁能给点建议?

提前致谢

【问题讨论】:

  • $sql = "UPDATE section_content SET title = '".$_GET['title']."', content = '".mysql_real_escape_string($content)."' WHERE id = '"。 $_GET['updateid']."' ";
  • 如果文本包含 & 符号,则插入和更新失败,我尝试了没有 & 符号的更新和插入成功

标签: php mysql


【解决方案1】:

如果您使用 mysql_ functions,请使用 mysql_real_escape_string() 转义它们,或者使用 PDO 准备查询。

【讨论】:

  • 是的,mysql_real_escape_string() 应该做得很好。
  • hmmm 似乎没有这样做,我的语法是 content = '".mysql_real_escape_string($content)."'
  • "mysql_real_escape_string" 这个扩展在 PHP 5.5.0 中被弃用,在 PHP 7.0.0 中被移除。 php.net/manual/en/function.mysql-real-escape-string.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-21
  • 2014-11-01
  • 1970-01-01
相关资源
最近更新 更多