Problem with post on_insert

QuestionsProblem with post on_insert
Andrea Campanella asked 4 months ago

I am trying to insert into a table with multiple columns using phpgrid, but in php I only show a few of these columns..

However one of these columns that I am not showing in the grid cannot be null.

So I am using

$e[“on_insert”] = array(“add_field”, null, true);



and then

function add_field($data)
global $g;

$query = “INSERT INTO `field` (`FieldFullName`, `FieldShortName`, `FieldTypeID`,`FieldCategory`,`SYSTEMCODE`,`StringLength`,`IntegerPlaces`,`DecimalPlaces`,`Notes`, `Status`, `InsertDate`, `UpdateDate`, `InsertUserID`, `UpdateUserID`, `Deleted`) VALUES (“;
$query = $query.”‘{$data[“params”][“FieldFullName”]}’,”;
$query = $query.”‘{$data[“params”][“FieldShortName”]}’,”;
$query = $query.”‘{$data[“params”][“FieldTypeID”]}’,”;
$query = $query.”‘1’,”;
$query = $query.”NULL,”;
$query = $query.”‘{$data[“params”][“StringLength”]}’,”;
$query = $query.”‘{$data[“params”][“IntegerPlaces”]}’,”;
$query = $query.”‘{$data[“params”][“DecimalPlaces”]}’,”;
$query = $query.”‘{$data[“params”][“Notes”]}’,”;
$query = $query.”‘{$data[“params”][“Status”]}’,”;
$query = $query.”‘2012-01-01 01:01:01.000000’,”;
$query = $query.”‘2012-01-01 01:01:01.000000’,”;
$query = $query.”‘1’,”;
$query = $query.”‘1’,”;
$query = $query.”‘0’)”;


When I try to insert using the + button above the grid, I enter fields and then press submit and I get this error:
Add Record
Couldn’t execute query. Field ‘FieldCategory’ doesn’t have a default value – INSERT INTO field (`FieldFullName`,`FieldShortName`,`FieldTypeID`,`StringLength`,`IntegerPlaces`,`DecimalPlaces`,`Notes`,`Status`) VALUES (‘textA’,’textB’,’1′,’1′,’2′,’3′,’notes’,’1′)

However the record is added correctly to the DB, but I can’t get rid of this error.

I also tried to set a default value for the column FieldCategory directly in the DB, for example say ‘3’, and if I do so I don’t get the error anymore but the columns is not set to ‘3’ instead of ‘0 that I need.

2 Answers
Abu answered 4 months ago

It looks like, the insert query is running twice. One by your function and one by grid itself … because you have set third param to true. Make it false and it will only run your function code and skip internal insert.

Pasting from docs:

[If you pass last argument as true, functions will act as a filter and insert/update in ->table will be performed by grid after your function. If last argument is set to false, only your function handler will be executed.

Andrea Campanella answered 4 months ago

thanks, confirmed

Your Answer

0 + 16 =

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 / 5. Vote count:

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

Let us improve this post!