【发布时间】:2015-07-15 21:30:16
【问题描述】:
当我显示来自 mysql 注释字段的文本时,我在 php 中使用以下函数:
nl2br(html_entity_decode($comment['message']))
当在我使用的查询中插入数据库时:
htmlentities($_POST['message'])
问题是,当我写一个像“Hello”这样的句子并显示它时显示:“Hello”
我怎样才能避免这种情况?
提前致谢。
更新:
这是插入:
$query = "INSERT INTO db.tablon (pID, userID, message, date_inserted, answer)
VALUES (:proyectoID, :userID, :mensaje, NOW(), :respuesta_mensaje_id)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':userID', $userID, PDO::PARAM_STR);
$stmt->bindParam(':proyectoID', $_POST['pID'], PDO::PARAM_STR);
$stmt->bindParam(':mensaje', htmlentities($_POST['respuesta_tablon']), PDO::PARAM_STR);
$stmt->bindParam(':respuesta_mensaje_id', $_POST['mID'], PDO::PARAM_STR);
$res = $stmt->execute();
【问题讨论】:
-
您的服务器必须启用魔术引号。禁用该设置。 php.net/manual/en/security.magicquotes.php
-
我已阅读该链接并指出从 PHP 5.4 中删除了该功能,我使用 PHP 5.4.3
-
你能发布你用于插入的代码吗?
-
好的,你正在绑定我认为这可能是一次清理数据的尝试。除了魔术引号或由开发人员编写时,我从未见过这种行为。
-
即使我删除了 htmlentities 函数,结果也是一样的。好奇!
标签: php html-entities