Heya not sure what the issue is with my on_after_insert function which performs an insert query.
Here is the function:
$e = array();
//on insert add a record to the notifications table and the notifications_status table
$e[“on_after_insert”] = array(“insert_data”, null, false);
function insert_data($data)
{
global$g;
$sql=”
INSERT INTO notifications
(
type
, type_sak
, sender_sak
, message
, sent_date
)
VALUES (
‘Notice Add’
,?
,62
,’test notice notification entry’
, NOW()
)”;
$g->execute_query($sql,$data[“item_sak”]);
}
$g->set_events($e);
Here is the column that is being called: through $data:
//ITEM_SAK
$col = array();
$col[“title”] = “Employee Name”; // caption of column, can use HTML tags too
$col[“name”] = “item_sak”; // grid column name, same as db field or alias from sql
$col[“editable”] = true;
$col[“hidedlg”] = true;
$col[“show”] = array(“list”=>true, “add”=>true, “edit”=>true, “view”=>true, “bulkedit”=>false);
$col[“editrules”] = array(“number”=>true);
$col[“editrules”] = array(“required”=>true);
$col[“edittype”] = “lookup”;
$col[“editoptions”][“sql”] = “select ” as k,’Select’ as v UNION select employee_sak as k, concat(lname,’, ‘,fname,’ ‘,middle_initial) as v from employee”;
$col[“editrules”][“readonly”] = true;
$cols[] = $col;
In your code, the line:
$g->execute_query($sql,$data["item_sak"]);
should be:
$g->execute_query($sql,array($data["item_sak"]));
You can also debug the query being executed by putting following line above execute_query call.
phpgrid_error($sql);
It will push the query as debug box to show what is being executed.