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 Link to comment https://forums.phpfreaks.com/topic/212105-im-inserting-html-code-into-a-mysql-db-i-need-it-outputted-as-plain-text/ Share on other sites More sharing options...
Andy-H Posted August 30, 2010 Share Posted August 30, 2010 Take a look at htmlentities. Link to comment https://forums.phpfreaks.com/topic/212105-im-inserting-html-code-into-a-mysql-db-i-need-it-outputted-as-plain-text/#findComment-1105358 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'))"; Link to comment https://forums.phpfreaks.com/topic/212105-im-inserting-html-code-into-a-mysql-db-i-need-it-outputted-as-plain-text/#findComment-1105361 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; Link to comment https://forums.phpfreaks.com/topic/212105-im-inserting-html-code-into-a-mysql-db-i-need-it-outputted-as-plain-text/#findComment-1105367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.