PDA

View Full Version : rich text editor displaying back from database



1kky
02-19-2008, 12:14 PM
1) Script Title: cms edit

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm

3) Describe problem: Hi, The problem iam having is that when i try to dispaly back the content from the db, the editor just disappers when it tries to display back the content, if i insert another tag it can display that but it doesn't display the the one i want, this is the code i have at the moment...

<?php # Script 12.3 - cmsadmin.php
//this is the main page for the site

//Set the page title and include the html header
$page_title = 'Admin Side';

require_once ('./includes/mysql_connect.php');
include('./includes/header.html');

if(isset($_GET['id']))
{
$query = "SELECT id, title, summary, contents ".
"FROM content ".
"WHERE id = '{$_GET['id']}'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
list($id, $title, $summary, $contents) = mysql_fetch_array($result, MYSQL_NUM);

$contents = htmlspecialchars($contents);
}
else if(isset($_POST['title']))
{
$id = $_POST['id'];
$title = $_POST['title'];
$summary = $_POST['summary'];
$contents = $_POST['contents'];

if(!get_magic_quotes_gpc())
{
$title = addslashes($title);
$summary = addslashes($summary);
$contents = addslashes($contents);
}

// update the article in the database
$query = "UPDATE content ".
"SET title = '$title', summary = '$summary', contents = '$contents' ".
"WHERE id = '$id'";
mysql_query($query) or die('Error : ' . mysql_error());
mysql_close();

echo "<p align='center'>Page updated</p>";

// now we will display $title & content
// so strip out any slashes
$title = stripslashes($title);
$summary = stripslashes($summary);
$contents = stripslashes($contents);
}
?>
<form name="edit" action="cms-edit.php" method="post" onsubmit="return submitForm();">

<input type="hidden" name="id" value="<?=$id;?>">

<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
updateRTE('rte1'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
alert("Submitted value: "+document.myform.rte1.value) //alert submitted value
return true; //Set to false to disable form submission, for easy debugging.
}

//Usage: initRTE(imagesPath, includesPath, cssFile)
initRTE("images/", "", "");
//-->
</script>

<div id="table">

<p class="blue">1. Enter the Title</p>

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
<tr>
<td bgcolor="#f7eedc">&nbsp;Title</td>
</tr>
<tr>
<td bgcolor="#f7eedc" width="100%"><input type="text" name="title" size="40" maxlength="60" id="title" value="<?=$title;?>"/></td>
</tr>
</tbody>
</table>
<br />

<p class="blue">2. Enter the Summary</p>
<p class="advice">A short summary of the content</p>

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
<tr>
<td bgcolor="#f7eedc">&nbsp;Summary</td>
</tr>
<tr>
<td bgcolor="#f7eedc" width="100%">
<textarea name="summary" cols="40" rows="5" class="box" id="summary"><?=$summary;?></textarea></td>
</tr>
</tbody>
</table>
<br />

<p class="blue">3. Enter the Content</p>
<script language="JavaScript" type="text/javascript">

</script>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
<tr>
<td bgcolor="#f7eedc">&nbsp;Content</td>
</tr>
<tr>
<td bgcolor="#f7eedc" width="100%"><script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//to sync only 1 rte, use updateRTE(rte)
//to sync all rtes, use updateRTEs
//updateRTE('rte1');
updateRTEs();
alert("rte1 = " + document.txteditor.rte1.value);


//change the following line to true to submit form
return false;
}

//Usage: initRTE(imagesPath, includesPath, cssFile)
initRTE("themes/default/images/", "", "");
//-->
</script>
<noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>

<script language="JavaScript" type="text/javascript">

//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
writeRichText('contents', '<?=$contents;?>', 520, 200, true, false);
//-->

</script></td>
</tr>
</tbody>
</table>
<br />

<div id="submitted"><input type="submit" name="save" id="save" value="Save Page" /></div>

</div>

</form>

<div id="bgbottom"><img src="themes/default/images/bgbottom.gif" width="785" height="75" alt="bottompanel"></div>

</div>

</body>

</html>


Please can you help ......

Thanks in advance

1kky
03-07-2008, 05:02 PM
thanks for the help, i have resloveed the problem

Kevin_UniCreation
09-15-2008, 08:47 AM
Please advise how you resolve the problem: rich text editor displaying back from database