...

View Full Version : insert HTML into Database and keeping formating



jokerswild
11-19-2011, 06:30 AM
ok I am work on a application that inserts HTML that was done with CKeditor found here http://cksource.com/ckeditor pretty simple to install and seems to work great other then when i click save it removes all the HTML formatting and turns it into a blob of run together text. I have tried man different things and still nothing seems to work

any help would be great here is my code



<?php
// this starts the session


include('../../system.php');

$get_page=mysql_query("SELECT * FROM ttd_special_offers WHERE id=1") or die (mysql_error());
$r=mysql_fetch_assoc($get_page);

$html = $r['offer'];

if(isset($_POST["Submit"])){
$editor_data = $_POST[ 'offer' ];
$clean_data=htmlentities($editor_data);
$p_data=$clean_data;

$up_data="update `ttd_special_offers` SET offer='$p_data' WHERE id=1";
mysql_query($up_data) or die (mysql_error());

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<link rel="stylesheet" type="text/css" href="../css/config.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action='page_manager.php?id=<?php echo $g_id ;?>' method='POST' name='offer_page'>
<input type="hidden" name="id" value="id">
<table width="100%" class="configuration" bgcolor="#F2F2F2" align="center">
<tr>
<th>Special Offers</th>
<th>
<table width="100%">
<tr>
<td align="center">
<input type="button" value="Close Configuration" onClick="window.location.replace('../frames/home.php');" name="close" class="buttonsubmit">
</td>
<td>

</td>
</tr>
</table>
</th>
</tr>
<tr>
<td width="25%" class="c_col_left" valign="top">Offer 1
</td>
<td width="75%" align="center" class="c_col_right" valign="top">
<textarea class="ckeditor" cols="60" rows="20" name="offer" id="offer"><?php echo $html ;?></textarea><script type="text/javascript">
window.onload = function()
{
CKEDITOR.replace( 'offer' );
};
</script>

</td>
</tr>
<tr>
<th width="100%" colspan="2">
<p style="text-align: center">
<input type="Submit" value="Submit" name="Submit" class="buttonsubmit">
</th>
</tr>
</table>
</form>

</body>
</html>

Adee
11-19-2011, 06:50 AM
because ur using htmlentities..........

jokerswild
11-19-2011, 06:56 AM
even with out it strips the HTML content

this is what i get without

here is a example say i use


<p>
blah blah blah&nbsp;<a href="http://google.com">http://google.com</a>&nbsp;<span style="font-size:24px;">some big text now this is what i &nbsp;get</span></p>


that in turn when i click submit does this

in the database

blah blah blah http://google.com some big text now this is what i get


because ur using htmlentities..........

loki421
11-19-2011, 03:45 PM
Hi,

I've used ckeditor before with no problems.

Have you tried just inserting the post['offer'] straight to the db? This will give you the raw input then you could build it up bit by bit, like the next step would be to escape the input with mysql_real_escape_string(), then if that's still adding it fine then you do the next step (whatever that me be that you want to do).

I simply passed my posted textarea input (ckeditor) to my db class, escaped as above and saved to the db. All HTML was saved as expected.

Hope this works for you :)

jokerswild
11-19-2011, 06:18 PM
yes I have tried straight POST...still striping the content i dont know why or understandably why....that when i started looking into other options


Hi,

I've used ckeditor before with no problems.

Have you tried just inserting the post['offer'] straight to the db? This will give you the raw input then you could build it up bit by bit, like the next step would be to escape the input with mysql_real_escape_string(), then if that's still adding it fine then you do the next step (whatever that me be that you want to do).

I simply passed my posted textarea input (ckeditor) to my db class, escaped as above and saved to the db. All HTML was saved as expected.

Hope this works for you :)

loki421
11-19-2011, 06:46 PM
Are you pasting into the textarea? Have you tried typing directly into the textarea and posting like that?

Without seeing your setup it's a bit tricky to figure out.

Like I say, I've never had any trouble with ckeditor, it works 'straight out of the box' and posted html to the db with no problems...

Don't know what else to suggest dude? :s



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum