Execute Query after Insert event

Execute Query after Insert event

hdsahdsa Posts: 7Questions: 0Answers: 0
edited October 2013 in Editor
Hello,
Im' new in DataTables and I need to do the following:
After Execute an Insert (clicking the button) , I need to execute a second MySQL query...
Were and how can I do That?

Thanks in advanced.

Replies

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Hi,

    What you would do is add:

    [code]
    if ( isset( $_POST['action'] ) && $_POST['action'] === 'create' ) {
    // ... do SQL insert
    }
    [/code]

    Immediately after the process() (or json() call depending on how you want the code ordered). You can use the sql() method of the Database class to execute raw SQL: http://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_sql

    Regards,
    Allan
  • hdsahdsa Posts: 7Questions: 0Answers: 0
    Thank you...

    I've got another question...

    I Have a form to get the following fiels...

    Editor::inst( $db, 'TEmpresas' )
    ->fields(
    Field::inst( 'Empresa' ),
    Field::inst( 'Morada' ),
    Field::inst( 'NIPC' ),
    Field::inst( 'Telefone' ),
    Field::inst( 'Email' )
    )

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


    And I need to update a table with the value inserted by the user in, for example, the field 'NIPC'....

    How can I do this?
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    The data submitted is available in $_POST['data']['NIPC'] (or exchange `NIPC` for any other variable that is being defined in Editor if you want to use others). rom there you can use it in an SQL query or anywhere else that you want to.

    Allan
This discussion has been closed.