Edit edits the row but also adds another row

Edit edits the row but also adds another row

shileshile Posts: 2Questions: 1Answers: 0

When i edit a whole row or only one column it does edit successfully but it also adds another row in database with those new values so of course when i refresh and get new data there is the new row and previous edited one...help?

Answers

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

    We'll need a little more information to be able to offer any assistance here. Could you show us the client-side and server-side code that you are using please? I presume it is Editor you are using?

    Allan

  • shileshile Posts: 2Questions: 1Answers: 0

    Here is the code...

    HTML

    <div id="meni">
    <table id="menu" class="table table-striped table-bordered" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Price</th>
                    <th>Calories</th>
                    
                </tr>
            </thead>
     
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Price</th>
                    <th>Calories</th>
                    
                </tr>
            </tfoot>
        </table>
    
    </div>
    

    JAVASCRIPT

    $(document).ready(function() {
    
    
    var editor;
    
    
    
        editor = new $.fn.dataTable.Editor( {
            ajax: "editor.php",
            table: "#menu",
            idSrc:"restaurant_id",
            fields: [ {
                    label: "Name:",
                    name: "name"
                }, {
                    label: "Price:",
                    name: "price"
                }, {
                    label: "Calories:",
                    name: "calories"
                },
                {   name:"restaurant_id",
                    type:"hidden",
                    def:$('#restaurant_id').val()
                }
            ]
        } );
        
        $('#menu').on( 'click', 'tbody td', function (e) {
            editor.inline( this );
        } );
        
        
        
        
     
        $('#menu').DataTable( {
            dom: "Tfrtip",
            ajax: "editor.php",
           
            columns: [
            
                { data: "name" },
                { data: "price"},
               { data: "calories"}
               
            ],
            tableTools: {
                sRowSelect: "os",
                aButtons: [
                    { sExtends: "editor_create", editor: editor },
                    { sExtends: "editor_edit",   editor: editor },
                    { sExtends: "editor_remove", editor: editor }
                ]
            }
        } );
    } );
    
    
    
    

    PHP

    <?php
     
    /*
     * Example PHP implementation used for the index.html example
     */
     include("session.php");
    // DataTables PHP library
    include( "php/DataTables.php" );
     
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
     
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'Menu' )
        ->fields(
            Field::inst( 'name' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'price' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'calories' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'restaurant_id' )
            
           
        )
       ->where('restaurant_id',$_SESSION['restaurant_id'])
        ->process( $_POST )
        ->json();
        
        
    
    <?php
    >
    ?>
    
    
    
  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    Very odd! The restaurant_id parameter is the only one that stands out for me that could potentially go wrong, but to be honest, I'm struggling to see how - it looks like it should be okay!

    Can you confirm what version of Editor you are using please? If not 1.4.2, could you try that.

    Could you also try it without the where condition and see if the same problem occurs?

    Thanks,
    Allan

This discussion has been closed.