jdock1 Posted August 30, 2010 Share Posted August 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 30, 2010 Share Posted August 30, 2010 Take a look at htmlentities. Quote Link to comment Share on other sites More sharing options...
jdock1 Posted August 30, 2010 Author Share Posted August 30, 2010 i was looking at that, i tried implementing it but it gave me a query error. This is what I had, what did I do wrong? $query = "INSERT INTO gencode (generated) VALUES ('(htmlentities)$code'))"; Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 30, 2010 Share Posted August 30, 2010 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.