我有一个工作正常的更新表格,没有CKeditor,textareas填充了数据库中的内容。
我只是想尝试实施CKeditor。我可以在这里输入文本,它将保存到数据库,但是当我想要更新时,文本不会自动填充到CKeditor中。
请有人可以提供一些帮助,以便将数据库中的内容输入CKeditor,就像它在分钟内进入textarea一样。
提前致谢。
<?php
if(!isset($_SESSION['user']))
{
header("Location: login.php");
}
//$vbCrLf = chr(13).chr(10);
$vbCrLf = "";
require ('mysqli.php');
//create and execute query
$query = 'SELECT PageId, PageTitle, PageContent, PageContent2 FROM pages ORDER BY PageId';
$result = $conn->query($query);
//create selection list
$DropDownList = "<select name='PageId' id='PageId' onchange='SelectChanged();'> ".$vbCrLf;
//Code below may need to be deleted
$DropDownList .= "<option value=''>--SELECT PAGE--</option> ".$vbCrLf;
// as it could give an error
while($row = mysqli_fetch_row($result))
{
$heading = htmlentities($row[0]);
$DropDownList .= "<option value='$heading'>".json_encode($row[1])."</option> ".$vbCrLf;
$PageTitlePhp .= 'PageTitleArray['.$heading.']='.json_encode($row[1]).';'.$vbCrLf;
$PageContentPhp .= 'PageContentArray['.$heading.']='.json_encode($row[2]).';'.$vbCrLf;
$PageContent2Php .= 'PageContent2Array['.$heading.']='.json_encode($row[3]).';'.$vbCrLf;
}
$DropDownList .= "</select> ".$vbCrLf;
$conn->close();
?>
<html>
<head>
<title>Update Page</title>
<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
</head>
<body>
<br>
<!-- php below; Creates a form to update database content -->
<form method="post" action="update_website_page_handle.php">
<table width="943" height="528">
<tr>
<td align="right"> </td>
<td height="32" colspan="2" align="left"><h1> Update Page </h1></td>
</tr>
<tr>
<td width="60" align="left"> </td>
<td width="134" height="32" align="left"><p>Select Page ID:</p></td>
<td width="733">
<?php echo $DropDownList; ?>
</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><p>Page Title:</p></td>
<td><textarea style="width: 500px; height: 50px;" name="PageTitle" id="PageTitle" class="heading"></textarea></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><p>Page Content:</p></td>
<td>
<textarea style="width: 500px; height: 200px;" name="PageContent" id="PageContent" class="date"></textarea>
</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><p>Extra Page Content:</p></td>
<td>
<textarea style="width: 500px; height: 200px;" name="PageContent2" id="PageContent2" class="details"><?php print $PageContent2Php; ?></textarea>
<script>
CKEDITOR.replace('PageContent2');
</script>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
<script language="Javascript" type="text/javascript">
var PageTitleArray = new Array();
<?php echo $PageTitlePhp; ?>
var PageContentArray = new Array();
<?php echo $PageContentPhp; ?>
var PageContent2Array = new Array();
<?php echo $PageContent2Php; ?>
function SelectChanged()
{
var PageId = document.getElementById('PageId').value;
document.getElementById('PageTitle').value = PageTitleArray[PageId];
document.getElementById('PageContent').value = PageContentArray[PageId];
document.getElementById('PageContent2').value = PageContent2Array[PageId];
}
SelectChanged(); // added to execute the function after loading to select first value.
</script>
</body>
</html>