How access row's data just after a create action

How access row's data just after a create action

jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
edited October 2013 in Editor
Hi Allan.
I,ve looked for in forum but I don´t find answer. Excuse me if you have answered this question yet.
I want to perform a second insert in my sql database just after a create action in my editor.

I use a create.php just like in your examples with this code :

include( "customer.php" );
$editor
->process($_POST)
->json();

I want use the data of the row I´ve inserted here to perform a second insert in another table of the database.
How can I refer to them in this create.php ?

Thanks.

Replies

  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    edited October 2013
    Hi,

    *edit* Sorry - I got myself confused with two very similar, but not the same, questions - this answer has been updated for this specific question...!

    To get the data, use the `data()` method rather than `json()` (you can then simply use `json_encode()` from PHP to echo out the JSON data, but `data()` will let you actually access the data of the row.

    So you would have something like:

    [code]
    $data = $editor
    ->process($_POST)
    ->data();

    if ( isset( $_POST['action'] ) && $_POST['action'] === 'create' ) {
    // .. row information is in $data['row']
    }
    [/code]

    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
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi again.
    I used only the code you propose to me, I didn´t add any line of code.
    I checked that in $data I got the row´s data I have created with an echo and after I deleted this echo.
    But in editor´s window I received:

    "An error has occurred - Please contact the system administrator"
    Do you know why ?

    Note.- The row was created correctly.

    Thanks
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi Allan.
    I solve it with this :

    $object = $editor->process($_POST) ;
    // Get data
    $data = $object->data();
    // Here I work with $data
    .......
    // Return result to the rutine create.php
    $object->json();

    With this code I don´t get the error and the row is created correctly.
    What is your opinion ?
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Sounds good to me! The error you were getting means that there was a JSON error, to diagnose we'd need to know what the error was, but your solution looks absolutely fine to me.

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Related to this question, when I delete a row I use your remove.php code :

    $editor
    ->process($args)
    ->json();

    I want use the data of the row I´ve deleted here to perform a second delete in another table of the database.

    How can I refer to them in this remove.php ?
This discussion has been closed.