Bill
Bill

Reputation: 19308

PHP PDO bindParam with html content

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();

Upvotes: 1

Views: 4051

Answers (1)

Pramendra Gupta
Pramendra Gupta

Reputation: 14873

use

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

instead of

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

Upvotes: 1

Related Questions