Custom Insert

Where do i have to place the custom functions for inserts (complex Updates)? Do i have to place it in the connector.php (for example basic_connector.php)?
In the following example, what does the $data parameter mean? Is $conn the connector object ($grid in 01_basic_connector for example)?

function my_update($data){ $price=$data->get_value("price"); $id=$data->get_value("id"); $conn->sql->query("UPDATE some_table SET price='{$price}' where id={$id}"); $data->success(); //if you have made custom update - mark operation as finished } $conn->event->attach("beforeUpdate","my_update")

THANKS

Where do i have to place the custom functions for inserts
You should place this function at the file where you initialize dhtmlxConnector object.

In the following example, what does the $data parameter mean?
This is DataAction object docs.dhtmlx.com/doku.php?id=dhtm … ion_object

docs.dhtmlx.com/doku.php?id=dhtm … or_event_o

Thanks for your answer. I still have a problem with the code. I’ve now created a function for the insert but when i want to show the table, nothing is shown on display. There is an error message but no text is shown inside the box of the error message. When i delete my function, everything is fine.
This is my function:

[code]function my_insert($action)
{
$logcallid = $action->get_id();
$source = $action->get_value(“Source”);
$num = $action->get_value(“Num”);
$msg = $action->get_value(“Msg”);

        $grid->sql->query("INSERT INTO SYS_LogCalls (LogCallID, Source, Num, Msg) VALUES ('{$logcallid}', '{$source}', '{$num}'), '{$msg}'");
        $action->success();
    }
    $grid->event("beforeInsert", "my_insert");[/code]

I have included “base_connector.php” and “grid_connector.php”…
Hope you can help.
Many thanks!

Try to enable server side logs for connectors, and provide log report for the problematic scenario.

$grid->enable_log("../../logfiles/error.log",true); is in my code…

and provide log report

There is no logfile in the directory. I think there is an php-file missing but i don’t know which one i have to include…This is what my file looks like:

[code]<?php
require_once(“…/config.php”);
$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);

require("../../codebase/grid_connector.php");
$grid = new GridConnector($res);
$grid->enable_log("../../logfiles/error.log",true);
$grid->dynamic_loading(100);
    $grid->sql->attach("Update","UPDATE SYS_LogCalls, SYS_LogCallDescription SET Source='{Source}', Num='{Num}', Msg='{Msg}', Application='{Application}', LogLevel='{LogLevel}', Text_en_US='{Text_en_US}' WHERE SYS_LogCalls.LogCallID = '{LogCallID}' AND SYS_LogCallDescription.LogCallID = '{LogCallID}'");
    function my_insert($action)
    {
        $logcallid = $action->get_id();
        $source = $action->get_value("Source");
        $num = $action->get_value("Num");
        $msg = $action->get_value("Msg");

        $grid->sql->query("INSERT INTO SYS_LogCalls (LogCallID. Source, Num, Msg) VALUES ('{$logcallid}', '{$source}', '{$num}'), '{$msg}'");
        //$lastid = $action->get_id();
        //$grid->sql->query("INSERT INTO SYS_LogCallDescription (LogCallID, Application, LogLevel, Text_en_US) VALUES ('{$lastid}', '{Application}', '{LogLevel}', '{Text_en_US}'");
        $action->success();
    }
    $grid->event("afterInsert", "my_insert");
    $grid->render_sql("SELECT lc.LogCallID, lc.Source, lc.Num, lc.Msg, lcd.Application, lcd.LogLevel, lcd.Text_en_US FROM SYS_LogCalls lc JOIN SYS_LogCallDescription lcd ON lc.LogCallID = lcd.LogCallID", "LogCallID", "Source,Num,Msg,Application,LogLevel,Text_en_US");       

?>[/code]
In the picture you can see what happens, when the insert function is activated:


Please provide content of the “error.log” file. We cannot detect why issue occurs by the empty alert.

I would like to give you the error log file but there is no error log file. It’s not in the folder that i wrote into the function. ($grid->enable_log("…/…/logfiles/error.log",true) Thats very strange.
Anyway now the table displays data because i found an error in my code. But when i try to insert something it didn’t work. When i try to insert new data in a row, the row is displayed red when i put new data in the cells.
This is my complete code:

[code]<?php
require_once("…/config.php");
$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);

require("../../codebase/grid_connector.php");
$grid = new GridConnector($res);
$grid->enable_log("../../logfiles/error.log",true);
$grid->dynamic_loading(100);
    $grid->sql->attach("Update","UPDATE SYS_LogCalls, SYS_LogCallDescription SET Source='{Source}', Num='{Num}', Msg='{Msg}', Application='{Application}', LogLevel='{LogLevel}', Text_en_US='{Text_en_US}' WHERE SYS_LogCalls.LogCallID = '{LogCallID}' AND SYS_LogCallDescription.LogCallID = '{LogCallID}'");
    /*function my_insert($action)
    {
        $logcallid = $action->get_id();
        $source = $action->get_value("Source");
        $num = $action->get_value("Num");
        $msg = $action->get_value("Msg");

        $grid->sql->query("INSERT INTO SYS_LogCalls (LogCallID, Source, Num, Msg) VALUES ('{$logcallid}', {$source}', '{$num}'), '{$msg}'");

        $newid = $action->get_new_id();
        $lcdid = $action->get_id();
        $application = $action->get_value("Application");
        $loglevel = $action->get_value("LogLevel");
        $text = $action->get_value("Text_en_US");

        $grid->sql->query("INSERT INTO SYS_LogCallDescription (LcdID, LogCallID, Application, LogLevel, Text_en_US) VALUES ('{$lcdid}', '{$newid}', '{$application}', '{$loglevel}', '{$text}')");
      
        $action->success();
    }*/
    $grid->render_sql("SELECT lc.LogCallID, lc.Source, lc.Num, lc.Msg, lcd.Application, lcd.LogLevel, lcd.Text_en_US FROM SYS_LogCalls lc JOIN SYS_LogCallDescription lcd ON lc.LogCallID = lcd.LogCallID", "LogCallID", "Source,Num,Msg,Application,LogLevel,Text_en_US");

?>[/code]
I just don’t understand why he does not write data in the two database tables…

I just don’t understand why he does not write data in the two database tables…
Most probably issue somewhere at custom SQL query.

Try to put log file at the same directory

$grid->enable_log(“error.log”,true);

Well after a few hours of trying with the beforeInsert a very strange thing happens. As soon as i click on the “add row” button (before i can input some data in the cells) it puts a new entry in my database table (SYS_LogCalls) but only in the primary key field (LogCallID) and it’s always the same number (2147483647).
Is there something wrong with the javascript event handler?

<input type="button" name="add" value="Neuer Eintrag" onclick="var id=mygrid.uid(); mygrid.addRow(id,'',0); mygrid.showRow(id);">