【发布时间】:2019-07-18 06:05:12
【问题描述】:
2019.07.19 更新:
使用
解决的问题$_REQUEST['editor1']
而不是 $_POST['editor1']。 不完全确定为什么。希望对遇到这个奇怪问题的人有所帮助。
=============================================
问题描述:
我正在将 CKeditor 集成到我的 HTML 表单中。 Ckeditor 成功显示在表单上,我可以输入一些数据。但是当我尝试发布表单以存储在数据库中时,我注意到数据库条目缺少所有 HTML 左括号和右括号。试图在互联网上搜索,但没有运气。请多多指教。
我的数据库字段是文本类型。
我已经用 TinyMCE 替换了 Ckeditor,但还是一样。
<div class="form-group">
<label for="content"><?=$str['content']?></label>
<div class="input-group mb-3">
<textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="20"></textarea>
</div>
</div>
<!-- Initializing the editor -->
<script src="//cdn.ckeditor.com/4.12.1/full/ckeditor.js"></script>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
我尝试用以下数据输入ckeditor textarea:
<h3><a href="https://stackoverflow.com/questions/22904776/insert-ckeditor-html-code-into-the-database">Insert ckeditor html code into the database - Stack Overflow</a></h3>
<p> </p>
<p><a href="https://stackoverflow.com/questions/22904776/insert-ckeditor-html-code-into-the-database"><cite>https://stackoverflow.com/questions/.../insert-ckeditor-html-code-into-the-database</cite></a></p>
但是当我存储在数据库中或检索 $_POST['editor1'] 数据时,我得到了这个:
h3a href=https://stackoverflow.com/questions/22904776/insert-ckeditor-html-code-into-the-databaseInsert ckeditor html code into the database - Stack Overflow/a/h3 p /p pa href=https://stackoverflow.com/questions/22904776/insert-ckeditor-html-code-into-the-databasecitehttps://stackoverflow.com/questions/.../insert-ckeditor-html-code-into-the-database/cite/a/p
所有左括号和右括号都丢失了。 我做错了什么?
下面是存储数据的代码:
if (isset($_POST['submit'])) {
$host = DB_HOST; /* Host name */
$user = DB_USER; /* User */
$password = DB_PASS; /* Password */
$dbname = DB_NAME; /* Database name */
$con = mysqli_connect($host, $user, $password, $dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$subject = $_POST['subject'];
$content = $_POST['editor1'];
$publish = $_POST['publish'];
$publish_date = $_POST['publish_date'];
$updated_by = $_SESSION['memberID'];
mysqli_query($con, " INSERT INTO tbl_announcement (subject, content, publish, publish_date, updated_by )
VALUES ( '$subject', '$content', '$publish' , '$publish_date', '$updated_by')");
【问题讨论】:
-
请上传您的 php 代码以便更好地理解。
-
使用
htmlentity()将括号转换为实体,并在您的视图中使用html_entity_decode();转换回 html 代码.. -
我只是保存 $field['myDBTextField'] = $_POST['editor1'];在数据库中,缺少左括号和右括号。即使我尝试 print_r($_POST) $_POST['editor1'] 也向我显示不带左括号和右括号的条目
-
视频在这里:streamable.com/n44em我试过使用serialize($_POST['editor1])和htmlentities(_$POST['editor1']),都没有运气
-
链接坏了..