Custom "on-update" causes update error

QuestionsCustom "on-update" causes update error
Steve Christiansen asked 11 years ago

Abu,

I'm trying to update a datetime column using the following:

$e["on_update"] = array("update_record", null, true);

$g->set_events($e);

function update_record($data)
{
$id = intval($_GET["rowid"]);
$data["params"]["id"] = $id;
$str = "UPDATE members SET datetime = NOW()
WHERE id = {$data["id"]}";
mysql_query($str);
}

The datetime column is populated correctly but any other modified field values are not updated. Error is "Couldn't execute query. Duplicate entry '0' for key 'PRIMARY' …" For whatever reason the query is setting the PK to 0. –> … ,id='0' WHERE id IN ('191') The IN clause is correct.

4 Answers
Abu Ghufran answered 11 years ago

This does not look to be an issue with on_update event.
You need to check what actually is first column of grid and it should be editable, not null and unique.

Steve Christiansen answered 11 years ago

This is a master-detail grid page. The master-grid is being updated and I also want to update the date of the modification which is stored in 'datetime' field of the master grid. Without the on-update section, the master grid update works fine. When I add the on-update section, as shown in original post, the 'datetime' field is updated correctly via the on-update, but other fields fail to be updated.

The beginning and end of the error output is shown in the original post:

Duplicate entry '0' for key 'PRIMARY' …" For whatever reason the query is setting the PK to 0. –> … ,id='0' WHERE id IN ('191')

The id is actually 191. I am doing something wrong.

Thanks for helping.

Steve Christiansen answered 11 years ago

Additionally, the first column in PK. Should this really be editable? It is not null and unique.

Abu Ghufran answered 11 years ago

Yes,

You can make it hidden OR set:

$col["editable"] = true;
$col["editrules"]["readonly"] = true;

The param names can creates little confusion but editable is required to get field posted on backend.

You can post the code link for review via pastebin.com

Your Answer

7 + 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 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?