【问题标题】:Escaping quotes before MySQL在 MySQL 之前转义引号
【发布时间】:2014-03-02 21:27:29
【问题描述】:

这里我有一个脚本来验证用户通过的描述:

if(strlen($_POST['descriprtion']) >250) {
    //Some error code here
} else { 
$description = $mysqli->escape_string(htmlentities(trim($_POST['description']))); }

现在,我用I'm testing 的描述进行测试。当我打印出页面时,我会给我这样的东西:

如您所见,单引号前有一个黑色斜线。

我正在考虑使用stripslashes(),但我应该在哪里使用它?

【问题讨论】:

标签: php mysql security


【解决方案1】:

当您想要回显变量时使用stripslashes()

echo $var;                 // --> I\'m testing. Not funny.
echo stripslashes($var);   // --> I'm testing. Not funny.

Working dmeo

【讨论】:

  • 谢谢。我也刚刚切换到准备好的陈述。虽然我没有逃脱它。它仍然返回斜杠。所以基本上,我仍然需要stripslashes 并使用准备好的语句
猜你喜欢
  • 2012-10-05
  • 2023-02-11
  • 2011-08-04
  • 2011-06-13
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 1970-01-01
  • 2010-10-27
相关资源
最近更新 更多