Jump to content

Retrieving HTML formatting with MySQL


Steppio

Recommended Posts

I'm currently using TinyMCE as a formatting tool in collaboration with a MySQL database, storing using PHP, however whenever i retrieve the formatted data from the Database it doesn't format the text, but echo's the data as shown below:

 

'<p style="text-align: center;">Example text Example te<strong>xt Example te</strong>xt Example text Example text Example text Example text Examp<span style="text-decoration: underline;">le text Exam</span>'

 

I know this is probably a very simple problem to solve and i'm just being an idiot but its making me tear my hair out. If anybody can help me out i'd be eternally grateful. Thanks in advance.

 

Steppio.

Link to comment
Share on other sites

This is probably not a MySQL problem (and I'm moving your post to the PHP area).

 

You should show code, like how you're displaying the info, when posting in this forum.

 

Use this to display:

http://us.php.net/manual/en/function.htmlentities.php

 

http://us.php.net/manual/en/function.html-entity-decode.php

 

http://us.php.net/manual/en/function.htmlspecialchars.php

 

Link to comment
Share on other sites

The code that i am using to enter the TinyMCE formatted content in to the MySQL database is as follows:

 

function add_news($userid,$newsdate,$newshead,$news)
{
$conn = db_connect();

// check if username is unique
$result = $conn->query("SELECT * from t_news where newshead='$newshead'");
if (!$result)
	throw new Exception('Could not execute query');
if ($result->num_rows>0)
	throw new Exception('That news title is taken '
								.'- go back and choose another one.');
// if ok put in db
$newsid = $conn->insert_id;
$result = $conn->query("INSERT into t_news values
								('$newsid','$userid','$newsdate','$newshead','$news')");
if (!$result)
	throw new Exception('Could not register article in the database '
								.'- please try again later.');

return true;
}

 

 

The code to retrieve and display the data is as follows:

 

<?php
function get_news1($id)
{
$conn = db_connect();
$result2 = $conn->query("SELECT newsid, userid, newsdate, newshead, news FROM t_news WHERE newsid='$id'"); 
	if (!$result2) 
	{ 
			exit('<p>Error performing query: ' . mysql_error() . '</p>'); 
	} 
	while ($row2 = mysqli_fetch_array($result2)) 
	{
	$newsid = $row2['newsid'];
	$user = $row2['userid'];
	$date = $row2['newsdate'];
	$head = $row2['newshead'];
	$news = $row2['news']; 
	}
?>

<table cellspacing="0" cellpadding="0" class="dbox" border="0">
<tr>
<td class="logo-s"><img src="images/dbox/logo-s.gif"></td>
<td class="date"><img src="images/dbox/date.gif"></td>
<td class="header" align="left"><h2><?php echo $head;?></h2></td>
<td class="end"> </td>
</tr>
	<tr>
<td class="sidestrip"> </td>
<td class="bg" colspan="2">



<table cellspacing="0" cellpadding="0" border="0" class="register">
	<tr>
	<td>
	<p><?php html_entity_decode($news); echo $news;?></p>
	<h2 align="right">From <?php echo $user;?> on <?php echo $date;?> </h2>
	<table class="register"><tr><td>
	<?php
	$user = $_SESSION['valid_user'];
	get_admin($user);
		if ($_SESSION['admin'] == 1)
		{
		echo "<br /><a href='deleteid.php?id=$newsid'>Delete/</a>";
		echo "<a href='editnews.php?id=$newsid'>Edit</a>";
		}
	?>
	</td>
	<td align="right">
	<?php
		if (isset($_SESSION['valid_user']));
		{
		echo "<br /><a href='deleteid.php?id=$newsid'>Post a Comment</a>";
		}
	?>
	</td></tr></table>
	</td>
   </tr>
</table>

</td>
<td class="l-line"> </td>
</tr>
		<tr>
<td class="sidestrip"> </td>
<td class="bg" colspan="2" align="right" style="height: 10px; padding-right: 20px;">
</td>
<td class="l-line"> </td>
</tr>
	<tr>
<td class="corner-s"> </td>
<td class="line-top" colspan="2"> </td>
<td class="br-corner"> </td>
</tr>
</table>


?>

 

I've tried the html_entity_decode function but it still displays no hint of formatting. Any help would be greatly appreciated. Thanks in advance.

 

Ste.

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.