PHP PDO bindParam with html content

拈花ヽ惹草 提交于 2019-12-29 07:18:31

问题


I try to save html content to the database, with ' or " it auto give a slash which is great so I don't have to do mysql_escape_string. However when I load up the string it shows as

<a href=/"yes/">test</a>

and if I save it again I got this

<a href=//"yes//">test</a>

Does that means when I echo out the string I should strip out the slash?

$html = '<a href="yes">test</a>';
$insertStatement = $pdo->prepare('insert into content (html) values (:html)');
$pdo->bindParam(:html, $html);
$pdo->execute();

回答1:


use

$pdo->bindValue(':html', $html, PDO::PARAM_STR);

instead of

$pdo->bindParam(:html, $html);


来源:https://stackoverflow.com/questions/10942972/php-pdo-bindparam-with-html-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!