Ok I need help running an insert query on another table after edit

QuestionsOk I need help running an insert query on another table after edit
Mike Olson asked 2 years ago

Here is my query. Everything in it parses fine but not sure why it errors out as I don’t get an actual error code or description.

 

//add transaction record after update
$e[“on_after_update”] = array(“update_data”, null, true);
$g->set_events($e);
function update_data($data)
{
global$g;
$g->execute_query(“INSERTINTO transactions
(item_sak
, item_type
,transtype
,transcode
,trans_date
performed_by)
VALUES ({$data[“params”][“employee_sak”]}
, ’employee’
, ‘EMPL’
, ‘002’
, NOW()
, $_SESSION[accounts_sak]
)”);
}

5 Answers
Abu Ghufran Staff answered 2 years ago

Perhaps a typo: INSERTINTO should be INSERT INTO (with a space in between)

Second, instead of passing query to try execute_query function, assign the query string to a variable e.g. $q and call:

$q = “INSERT INTO …. “;
phpgrid_error($q);

This will push the whole query in error message window for you to debug.

You can also use:
error_log($q);
and see php error log file.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mike Olson answered 2 years ago

I think that is a paste formatting issue. It isn’t like that in the actual code.

 

I will try the other suggestions

Mike Olson answered 2 years ago

But there was another sql error that I didn’t notice before thanks to your debugging code! Hopefully this fixes it

Mike Olson answered 2 years ago

Ok so I found the actual issue that I am having. I am trying to insert employee_sak which is set to edit=false as shown below. It is also the first column in my grid. How can I get that value so I can use it in my insert on_update?

 

//EMPLOYEE_SAK
$col = array();
$col[“title”] = “Employee Sak”; // caption of column, can use HTML tags too
$col[“name”] = “employee_sak”; // grid column name, same as db field or alias from sql
$col[“show”] = array(“list”=>false, “add”=>false, “edit”=>false “view”=>false, “bulkedit”=>false);
$col[“editable”] = true;
$col[“hidden”] = true;
$col[“hidedlg”] = true;
$cols[] = $col;

Abu Ghufran Staff answered 2 years ago

To get primary key column in callback functions, you need to use with params, e.g.

$data["employee_sak"]
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

14 + 12 =

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?