Passing parameter to Query

Passing parameter to Query

VAILLY OlivierVAILLY Olivier Posts: 19Questions: 0Answers: 0

Sorry to be back but i follow examples and it did not work !!!!

I pass a parameter to php script by ajax
POST parameter value is ok in Firefox debug console
When i try to submit some changes (by Editor), in php script i have error on "undefined index value" for my parameter !!!!!

my code

// DataTables PHP library and database connection
include( "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\Upload,
        DataTables\Editor\Validate;

// Build our Editor instance and process the data coming from _POST
$editor=Editor::inst( $db, 'stat_tocama_budget', 'cle' )
        ->fields(
                Field::inst( 'dimension_client.code' )
                        ->set( false ),
                Field::inst( 'dimension_client.nom' )
                        ->set( false ),
                Field::inst( 'dimension_produit.code' )
                        ->set( false ),
                Field::inst( 'dimension_produit.nom' )
                        ->set( false ),
                Field::inst( 'stat_tocama_budget.somme_qte_n_1' ),
                Field::inst( 'stat_tocama_budget.somme_ca_n_1' ),
                Field::inst( 'stat_tocama_budget.somme_tonnage' ),
                Field::inst( 'stat_tocama_budget.px' ),
                Field::inst( 'stat_tocama_budget.somme_ca' ),
                Field::inst( 'stat_tocama_budget.somme_qte_budget' ),
                Field::inst( 'stat_tocama_budget.px_budget' ),
                Field::inst( 'stat_tocama_budget.somme_ca_budget' ),
                Field::inst( 'stat_tocama_budget.valide' )
                    ->setFormatter( function ( $val, $data, $opts ) {
                        return ! $val ? 0 : 1;
                } )
        );
$editor->leftJoin('dimension_vendeur', 'dimension_vendeur.cle_vendeur', '=', 'stat_tocama_budget.cle_vendeur1');
$editor->leftJoin('dimension_client', 'dimension_client.cle_client', '=', 'stat_tocama_budget.cle_client');
$editor->leftJoin('dimension_produit', 'dimension_produit.cle_produit', '=', 'stat_tocama_budget.cle_produit');
$editor->where( function($q){
            $q->where('dimension_vendeur.code', ':user_code', '=', false);
            $q->bind( ':user_code', $_POST['user_code'] );
        });
$editor->process( $_POST );
$editor->json();

Error message from Debug :

<br />
<b>Notice</b>:  Undefined index: user_code in <b>/var/www/php/table.stat_tocama.php</b> on line <b>49
</b><br />
{"data":[]}

I've tried many things and no one work !!
Thanks for help

Replies

  • VAILLY OlivierVAILLY Olivier Posts: 19Questions: 0Answers: 0

    Precision : when i "bind" to a static value, it works ...... :(

    $editor->where( function($q){
                $q->where('dimension_vendeur.code', ':user_code', '=', false);
                $q->bind( ':user_code', 'static_user_code' );
            });
    
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    $_POST['user_code']

    Suggests that you are not submitting a POST parameter called user_code. How are you currently attempting to submit it? I don't think this is an Editor error.

    Allan

  • VAILLY OlivierVAILLY Olivier Posts: 19Questions: 0Answers: 0

    I check in Firefox debug and my parameter is POSTed !

    My JS code :

    (function($){
    $(document).ready(function() {
            var user_code = $("#user_code").text();
            var editor = new $.fn.dataTable.Editor( {
                    ajax: 'php/table.stat_tocama.php',
                    type: 'POST',
                    data: {user_code:user_code},
                    table: '#stat_tocama',
    

    and user_code is well filled with my right value
    :(

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you link to the page so I can take a look please?

    Allan

This discussion has been closed.