Editor Not Saving when enter pressed

Editor Not Saving when enter pressed

BadBryanBadBryan Posts: 7Questions: 1Answers: 0

I have a very simple page based closely on the examples you provide for a left join.

http://offwidth.com/stms/teams.html

All works very nicely, display, dropdown, the joined table data, however when editing, a new selection is made, and update selected, it doesn't save.

When trying to create a new record, the editor screen refreshes with "A system error has occurred"

in the debugger/resource log I get the following:

Warning: require(/hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Exception/Exception.php): failed to open stream: No such file or directory in /hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Bootstrap.php on line 43

Fatal error: require(): Failed opening required '/hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Exception/Exception.php' (include_path='.:/usr/local/lib/php-5.3.29-amd64/lib/php') in /hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Bootstrap.php on line 43

I saw a thread from 2013 where someone had a similar problem and Allan asserted that a bug in the (then) current Editor release was causing an issue that obfuscated the actual problem.

Any thoughts?

Thanks

Bryan

Replies

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    HI Bryan,

    It looks like this might have crept back in. Its a namespacing issue which doesn't effect all versions of PHP which is why it is possible for this to raise its ugly head again. It particularly effects old versions of PHP such as 5.3.x.

    Basically the Exceptions that Editor throws has to be prefixed with a \ to make them load correctly.

    I've just grep-ed the code and found two references to PDOException without a leading backslash (in Database/Drivers/Mysql/Query.php and Database/Drivers/Postgres/Query.php). It would be with adding a back slash in front of those two statements - both in the _exec functions for their respective files.

    I'm not convinced that will solve it though since the error message doesn't refer to the PDO aspect.

    What database are you using? Could you also show me the code in the table.teams.php file please?

    Thanks,
    Allan

  • BadBryanBadBryan Posts: 7Questions: 1Answers: 0
    edited April 2017

    Thanks Allan.

    using mysql 5.6.35

    here is the table.teams.php content

    <?php
    
    /*
     * Editor server script for DB table teams
     * Created by http://editor.datatables.net/generator
     */
    
    // 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\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'teams', array('teamName','coaches_coaches_ID'))
        ->fields(
            Field::inst( 'teams.teamName' ),
            Field::inst( 'teams.teamDescription' ),
            Field::inst( 'coaches.coaches_ID' )
                ->options(Options::inst()
                    ->table('coaches')
                    ->value('coaches_ID')
                    ->label(array('firstName','lastName'))
                )
                    ->validator('Validate::dbValues'),
            Field::inst('coaches.firstName'),
            Field::inst('coaches.lastName')
        )
        ->leftJoin('coaches','teams.coaches_coaches_ID','=','coaches.coaches_ID')
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    Thanks! Could you add ->tryCatch( false )->debug( true ) immediately before the ->process( $_POST ) line please? Then when you submit the data to the server, what does the JSON returned from the server look like?

    That will disable Editor's try / catch, which might give us more debugging information, and if it gets far enough some information about the SQL being executed.

    Allan

  • BadBryanBadBryan Posts: 7Questions: 1Answers: 0

    added the code as requested.

    on normal page load of the teams page (no edit or update attempt) the table.teams.php returns the following json: (see attached file) I hadn't provided that before.

    When I run a 'create' I get the following:

    Warning: require(/hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Exception/Exception.php): failed to open stream: No such file or directory in /hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Bootstrap.php on line 43

    Fatal error: require(): Failed opening required '/hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Exception/Exception.php' (include_path='.:/usr/local/lib/php-5.3.29-amd64/lib/php') in /hermes/walnaweb10a/b131/moo.bryanforsyth/stms/php/lib/Bootstrap.php on line 43

    Which doesn't seem to be any different.

    Thank

    Bryan

  • BadBryanBadBryan Posts: 7Questions: 1Answers: 0

    Any thoughts on this Allan?

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    Hi Bryan,

    Sorry about the delay!

    I think I've just found it. In the Editor.php file, in the second last method (_pkey_validate_insert) you will find:

                    throw new Exception( "When inserting into a compound key table, ".
                        "all fields that are part of the compound key must be ".
                        "submitted with a specific value.", 1
                    );
    

    The Exception should have a leading \ for compatibility with PHP 5.3 - e.g.:

                    throw new \Exception( "When inserting into a compound key table, ".
                        "all fields that are part of the compound key must be ".
                        "submitted with a specific value.", 1
                    );
    

    That said, you will still get an error message, but a "controlled" on this time!

    Regards,
    Allan

  • BadBryanBadBryan Posts: 7Questions: 1Answers: 0

    Thank you Allan, that change did produce a 'controlled' error. I have it working now, I found some errors in my join syntax.

    Best

    Bryan

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    Phew - got there in the end! Thanks for letting me know about this issue. It will be fixed for 1.6.2.

    Allan

  • saee2838saee2838 Posts: 18Questions: 6Answers: 0

    hi
    allan
    i have problem

    [04-Mar-2019 21:42:39 Asia/Tehran] PHP Fatal error:  Uncaught exception 'Exception' with message 'When inserting into a compound key table, all fields that are part of the compound key must be submitted with a specific value.' in /home/vpn/domains/universkate.ir/public_html/includes/datatableseditor/php/Editor/Editor.php:2032
    Stack trace:
    #0 public_html/includes/datatableseditor/php/Editor/Editor.php(1068): DataTables\Editor->_pkey_validate_insert(Array)
    #1 public_html/includes/datatableseditor/php/Editor/Editor.php(924): DataTables\Editor->_insert(Array)
    #2 public_html/includes/datatableseditor/php/Editor/Editor.php(689): DataTables\Editor->_process(Array)
    #3 public_html/includes/datatableseditor/examples/php/event_levels.php(80): DataTables\Editor->process(Array)
    #4 {main}
      thrown in public_html/includes/datatableseditor/php/Editor/Editor.php on line 2032
    
  • saee2838saee2838 Posts: 18Questions: 6Answers: 0

    i want check database if row with same value in event_level and event_id not available in the database
    isert the new row
    if available show error

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    A global validator is the way to do that. Query the database to see if the values are present or not. If in error then return a string with the error message from the validator. If valid return true.

    Allan

This discussion has been closed.