Update table, no error no update?

Good morning, please excuse the simplicity of this question but I am really struggling to resolve. I have inherited a CRM system and have come across an issue on updating records in a table, the insert works fine as below when attached to the OnAfterInsertRecord event

$lastInsertId = $this->GetConnection()->GetLastInsertId();
$sql = sprintf(“INSERT INTO tbl_lead (client_id, Cost) VALUES(%d, ‘%s’);”, $lastInsertId, $rowData[‘Cost’];
$this->GetConnection()->ExecSQL($sql);

However, the update doesnt actually update, no error on page just nothing changes, this is attached the OnAfterUpdateRecord event.

$sql = sprintf(“UPDATE tbl_lead SET Cost = ‘%s’ WHERE LID = %d;”, $rowData[‘Cost’], $rowData[‘LID’]);

Can anyone see anything obvious why this wouldn’t work, or is it being added to the wrong event?

Thank you

Per the documentation for GetLastInsertID();

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.
This means that your code should work. But, as you see, this pertains only to Auto_Incremented fields. Have you made sure that your previous query has the id set to Auto-Increment? Next, you only show the query being executed, no error checking. Perhaps you should add a line to see if an error was thrown. You would check that in $this->GetConnection()->errorCode();

Not sure if this helps, but, hope it does!

I would print the query, and run it manually to see what happens.

Sponsor our Newsletter | Privacy Policy | Terms of Service