0

i am trying to display html values from my database into a web page. i am using tinymce as text editor. the data already stored as html values but when i tried to display it to a web page, the values display like this. example:

<p>THIS IS&nbsp;<strong>APPLICATION MANAGEMENT</strong></p>

my code to display is

<?php

$user_name = "BLANK";
$password = "BLANK";
$database = "BLANK";
$server = "BLANK";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM service WHERE service_id=1";
$result = mysql_query($SQL);

while ( $db_field = mysql_fetch_assoc($result) ) {

print $db_field['contents'];
}

mysql_close($db_handle);

}
else {

print "Database NOT Found ";
mysql_close($db_handle);

}

?>

my question is how can i display that html values exactly like when i am using tinymce. what i mean is i want to display that html value like this:

<p>THIS IS&nbsp;<strong>APPLICATION MANAGEMENT</strong></p>

to this

THIS IS APPLICATION MANAGEMENT

hope anybody can assist me..

caxs
  • 5
  • 3
  • 1
    `echo htmlspecialchars($db_field['contents'])`? And is application management the new Sparta? – Marc B Nov 28 '14 at 15:20
  • it is not working..it show this <p>THIS IS&nbsp;<strong>APPLICATION MANAGEMENT</strong></p> and what do you mean by new sparta – caxs Nov 28 '14 at 15:22
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Nov 28 '14 at 15:27
  • just a joke, referring the movie "the 300": "THIS IS SPARTA!" – Marc B Nov 28 '14 at 15:30
  • the sparta that i know is from a korean variety show :D..by the way, thanks for the help.. – caxs Nov 28 '14 at 15:45

1 Answers1

0

You're looking for the problem in the wrong place.

When you put the data into the database in the first place, it looks like your code is expecting plain text input and converting it to HTML before passing it to the query.

Don't do that.


As a hack, you could run the data through htmlspecialchars_decode when you pull it out of the database, but that's not solving the real problem.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • any suggestion how can i display the html?i am new to programming. i want to use like joomla post style when you post some article and can choose whatever html to be use. – caxs Nov 28 '14 at 15:31
  • thank you..it already display in a way that i want..will alert about the obselete API in the future..thanks again – caxs Nov 28 '14 at 15:43