on_after_insert query not working

Questionson_after_insert query not working
Mike Olson asked 11 months ago

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;

1 Answers
Abu Ghufran Staff answered 11 months ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

1 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?