dongzhong5573 2017-03-07 10:39
浏览 47

CKEditor没有保存在utf-8中

I will try to be quick and easy to understand it. I'm having a problem with my project in PHP which I can't do anything to fix it, I have a instance of CKEditor in my website.

This is the config and the instance:

    <script src="assets/ckeditor/ckeditor.js" charset="UTF-8"></script>

<textarea class="ckeditor" name="editor1" id="editor" rows="10" cols="80" required value="<?php if($error) echo $profdesc; ?> ">
            <?php echo $profdesc; ?>
    </textarea>

    <script>
      CKEDITOR.replace('editor1', {
        contentsCss: "assets/ckeditor/test.css",
        uiColor: '#428bca',
        extraPlugins: 'wordcount,lineheight,colorbutton,smiley',
                    wordcount: {
                        showWordCount: true,
                      showParagraphs: false,
                      showCharCount: true,
                        maxCharCount: 3000,
                        paragraphsCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationparagraphs").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - paragraphs").show();
                        },
                        wordCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationword").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - word").show();
                        },
                        charCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationchar").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - char").show();
                        },
                        charCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationchar").css("background-color", "white").css("color", "black").hide();
                        },
                        paragraphsCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationparagraphs").css("background-color", "white").css("color", "black").hide();
                        },
                        wordCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationword").css("background-color", "white").css("color", "black").hide();
                        }
                    }
                });
  </script>

Everything works fine.. until I update the "description" with this editor, I have all my tables and mysql to UTF-8, or at least I think I have it. It could be a problem with the UPDATE SQL, here is the rest of the code. In this case I'm trying to save "Olá" in the DB.

if(mysqli_query($con, "UPDATE users SET username='" . $name1 .
       "',description='" . $descr . "',gender='" . $gender .
       "',location='" . $location . "',ocupation='" . $ocupation .
       "' WHERE user_id = '" . $_SESSION['usr_id'] . "'"))

This is the result on the DB: enter image description here

  • 写回答

1条回答 默认 最新

  • dqvj51875 2017-03-07 11:41
    关注

    I managed to fix it! All I had to do was to put a:

    mysqli_set_charset( $con, 'utf8');
    

    before the:

    if(mysqli_query($con, "UPDATE users SET username='" . $name1 . "',description='" . $descr . "',gender='" . $gender . "',location='" . $location . "',ocupation='" . $ocupation . "' WHERE user_id = '" . $_SESSION['usr_id'] . "'")) {
    

    And the result was: "Olá"

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改