Jump to content

Im inserting HTML code into a mysql DB, I need it outputted as plain text?


jdock1

Recommended Posts

Im inserting HTML into a database, and then outputting it on a PHP page. Its an iframe code, so when I output it, it shows the iframe. I need it to just display the HTML code. How can I do this? I thought it would be something simple but I can find anyway to do it.

 

Help very appreciated!!

 

Thanks

Use mysql_real_escape_string when using user-inputted data in a query, then use stripslashes and htmlentities on data when displaying (echo'ing) it.

 

i.e.

$query  = "INSERT INTO gencode (generated) VALUES ('" . mysql_real_escape_string($code) . "')";
$result = mysql_query($query)or trigger_error(mysql_error());

 

Now where the code should be displayed


//pull the data from the database.
$query  = "SELECT generated FROM gencode ORDER BY table DESC";
$result = mysql_query($query)or trigger_error(mysql_error());

   while($row = mysql_fetch_row($result)) :
      echo stripslashes(htmlentities($row[0], ENT_QUOTES, 'UTF-8', false));
   endwhile;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.