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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.