0

I want to insert html-code in database. How can I correctly escape string?

$html = '<tag>';
$sql = 'UPDATE table SET text = ? WHERE id = 1';
$stmt = sqlsrv_prepare($conn, $sql, array(&$html));
sqlsrv_execute($stmt);

This code throw error: Incorrect syntax near '<'.

Artem
  • 517
  • 1
  • 7
  • 24

1 Answers1

-2

Escape the HTML with

htmlspecialchars($html)

This function changes < to the HTML code for &lt;

This will fix you problem.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
KBeckers
  • 416
  • 4
  • 12