【发布时间】:2012-12-28 13:04:50
【问题描述】:
我试过这样:
$desc = mysql_real_escape_string($_POST['description'][$i]);
然后尝试将变量 $desc 插入 MySQL,我已经尝试过:
'".mysql_real_escape_string($desc)."'
作为实际插入查询的一部分。两者都不起作用。
我得到1x10-10 而不是1x10-10' pine。
一切都在第一个单引号处被切断。我什至尝试过:
$desc = mysql_real_escape_string("1x10-10' pine")`
看看会发生什么,以及添加斜线的情况。
有什么建议吗?
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial. -
你的 MySQL 字段是否足够长,可以容纳整个字符串?
-
生成的语句看起来如何。请提供完整的声明或至少提供这段代码的上下文。
-
htmlspecialchars 不能搞乱查询。此函数用于 HTML 输出,而不是 SQL
标签: php mysql database escaping