Query runs twice

1

the following ajax function sends the parameters correctly:

    function concatenaredicion(idarchivoaeditar) {
    var contenidoagregar = CKEDITOR.instances['editor1'].getData();
    data = {
        "texto":contenidoagregar,
        "idinforme":idarchivoaeditar
    }
    $.ajax({
        type: 'POST',
        data: data,
        url: 'php/editainforme.php',
        success: function name(data) {
            alert(data);
        }
    })
}

The problem is that file .php executes the query but concatenates twice the same value

<?php
    require_once('../conexion.php');
    $texto = $_POST['texto'];
    $informe = $_POST['idinforme'];
    $stmt = mysqli_prepare($con, "UPDATE archivos_informes SET contenido = CONCAT(contenido,?)
        WHERE idArchivo = ? ");
        mysqli_stmt_bind_param($stmt, "si", $texto,$informe);
    if (isset($_POST["texto"]) && !empty($_POST["texto"])) {
        mysqli_stmt_execute($stmt);
        if (!$stmt->execute()) {
            echo "Falló la ejecución";
        }else{
            echo "Informe actualizado";
        }
    }else{  
        echo "Agruegue un contenido";
    }
?>  

The problem itself is as follows: If in my variable $texto has a value of <p>1</p> in my database is concatenated twice as follows: <p>1</p><p>1</p>

    
asked by arglez35 28.08.2018 в 23:25
source

1 answer

3

Your problem is here:

mysqli_stmt_execute($stmt);
if (!$stmt->execute()) {

You are running $stmt twice. You only need to run once like this:

if (!$stmt->execute()) {
    
answered by 28.08.2018 / 23:31
source