Problem to save data with CKEDITOR PHP AND MYSQL

4

I'm trying to insert data from a CKEDITOR into a mysql database with php, but I'm trying to capture that data through different modes that I found on the web, but I can not insert the CKEDITOR content in a field of the BD: htmlentities, htmlspecialchars, but I do not know how I can capture and insert that data. I leave the code I use, and if you could help me achieve it.

//Primero a través de un js guardo los datos:

var editor= CKEDITOR.instances['editor'].getData();
//y así envío el dato con ajax y metodo GET 

Then in the PHP file, using the GET method to insert:

caracteristica_producto=$conexion->real_escape_string($_GET['editor']); 
    
asked by Joseph Abdias Alejandro Tinoco 05.10.2016 в 02:48
source

4 answers

1

To capture the data of ckeditor , you can do it with php

HTML

<textarea name="texto" id="editor1"></textarea>

JAVASCRIPT

<script type="text/javascript">
    CKEDITOR.replace( 'editor1',
        {
            lang: 'es',
            skin: 'office2013',
            allowedContent: true,
            ignoreEmptyParagraph: false,
            enterMode: CKEDITOR.ENTER_BR
        });
</script>

PHP

<?php
    $contenido = addslashes($_POST['texto']);
?>

And if you do it with ajax , it has to be by post

AJAX

var data = $("#idFormulario").serialize();
$.ajax({
      type: "POST",
      url: "url",
      data: data,
      success: function(data) {

      }
});
    
answered by 07.10.2016 в 06:57
1

Ckeditor saves html if or if, make sure that the field where it is saved is preferably VARCHAR and do not apply any filter to the variable that receives the contents of the ckeditor, save it as is, that is, do not use htmlentities or anything like that and obviously send by POST.

    
answered by 12.10.2016 в 04:06
0

Have you already tried adding adds?

$conexion->addslashes($_GET['editor']); 
    
answered by 05.10.2016 в 20:05
0

Did you validate that your editor variable contains something? The first thing you should do is validate until part of your information is traveling; it is likely that you are not correctly capturing the control data.

    
answered by 07.10.2016 в 06:22