Error when editing the table

Error when editing the table

ostmalostmal Posts: 102Questions: 33Answers: 0

Hello!
I really need your help.
I have simplified the situation to the maximum to make it clear.
So, I pass the variable "zp" to the server, filtering takes place on it.
The variable is EXACTLY passed.
When trying to edit an entry in the table, an error occurs: "An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL...." In
the debugger:
«{"fieldErrors":[],"error":"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND id = '12'' at line 1","data":[],"ipOpts":[],"cancelled":[]} "It

Is interesting that if I forcibly assign the value of the variable ($zp = "200";) at the beginning of the PHP file, everything is fine!
Test example:
http://www.a0250268.xsph.ru/index.php

JS

(function($){
$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: '/abc_crm/dt/my/kv/kv.php',
        table: '#aaa_kv',
        fields: [
            {
                label: "fio:",
                name: "fio_name"
            }
        ]
    } );

    var table = $('#aaa_kv').DataTable( {
        dom: 'Bfrtip',
        ajax: {
            url: '/abc_crm/dt/my/kv/kv.php',
            type: 'post',
            data: { zp : "200" }
        },
        paging: true,
        columns: [
            {data: "id"},
            {data: "zp"},
            {data: "fio_name"}
        ],
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    } );

} );
}(jQuery));


PHP

<?php

$zp = $_POST['zp'];
header("X-DHTML-CONSOLE-MSG: " . $zp);

// $zp = "200";

// DataTables PHP library and database connection
include( "../../prog/php/lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'aaa_fio', 'id' )
    ->fields(
        Field::inst( 'id' ),
        Field::inst( 'fio_name' ),
        Field::inst( 'zp' )
    )

    ->where( function ( $q ) use ( $zp ) {
            $q->where( 'zp', "($zp)", 'IN', false );
    } )

    ->process( $_POST )
    ->json();


This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949
    Answer ✓

    I think you will want to use the Editor's ajax.data to pass the zp value as that is the ajax request being sent when using the Editor features. Might also need to set the type to POST.

    Kevin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    It works! Thank you for your help!

Sign In or Register to comment.