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.
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.
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.
Additionally, the first column in PK. Should this really be editable? It is not null and unique.