I'm stuck with trying to figure out how to display html tags inside of a mysql table. I've tried using addslashes, mysql_real_escape_string, as well as stripslashes to view the tags properly. Everytime I view the data through the browser, it shows the text of the html. Example:
I have this in a mysql database table:
<strong>Test</strong>
It should display as this when viewed on a webpage: Test
But instead, it displays <strong>Test</strong>
My PHP code to view the content is:
<?php
require_once("inc.php"); //This includes the configuration for mysql database
?>
<html>
<head>
</head>
<body>
<p>
<?php
$conn = mysql_connect(HOST,USER,PASS) or die(mysql_error());
mysql_select_db(NAME) or die(mysql_error());
$sql = "SELECT * FROM events";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
echo(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
}
mysql_close($conn) or die(mysql_error());
?>
</p>
</body>
</html>
Use htmlspecialchars_decode
Replace the following line
echo(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
With
echo htmlspecialchars_decode(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With