help with stock update

Hello good morning, I need help.
I have two tables:ARTICLE TABLE
Cod. (Primary key)
Article (Varchar)
Stock (Int)ORDER TABLE
order_id (Primary key)
Cod_Article (Int)
Quantity (Int)The tables are related
The Cod. Field of the Articles table is related to the Cod_Article field of the Orders table.
I need to subtract the amount from the stock and update the stock field with the new value.I have tried for several hours but without positive results.
I believe server event
Row_Inserted
with this repository code// Update record
// NOTE: Modify your SQL here, replace the table name, field name and field values
$ myResult = Execute (“UPDATE MyTable SET Field1 = Value1, Field2 = Value2, Field3 = Value3 WHERE MyField = XXX”);But I can’t get it.I’m trying to learn. Surely it must be something silly, but I can’t solve it by my means. I am new to the subject and I have searched for information about it but I cannot make this work.
I am using phpmaker 2020.
Thanks for your help.
P.S. Sorry for my English.

Simply put the following code in “Row_Inserted” server event that belongs to the “orders” table:Execute("UPDATE articles SET Stock = Stock - " . $rsnew[“Quantity”] . " WHERE Cod = " . $rsnew[“Cod_Article”]);

thanks mobhar for your prompt response, the code you shared does not fulfill its function, does not update the stock in the articles table. What else can I try?

In which page did you add a new record? Is it from a single “Add Page”, or is it from a “Master/Detail Add Page”?

from the orders page add record …

It should work as long as you have already selected the “Cod_Article” and filled-in the “Quantity” value from “orders” table.Please enabled the Debug mode, and see whether any error message shown.

el codigo es
// Row Inserted event
function Row_Inserted($rsold, &$rsnew) {
//echo “Row Inserted”// Update record
// NOTE: Modify your SQL here, replace the table name, field name and field values
$myResult = Execute(“UPDATE Artículos SET Stock=Stock-”.$rsnew[“Cantidad”]." WHERE Cod.=".$rsnew[“Cod_Artículos”]);
}Enable the debugger and it doesn’t throw errors.

The code that has shared me is working, I appreciate the attention

If only from the beginning you sent the original tables schema and also you posted your code, then the solution can be given straightforward.

another query, if I wanted to do the same, but this time when deleting an order record, that the stock of the articles table is updated again I suppose I should go in row_deleted but this code does not unite in that event
$ myResult = Execute (“UPDATE Items SET Stock = Stock +”. $ rsnew [“Quantity”]. “WHERE Cod. =”. $ rsnew [“Article_Code”]);
}
could you guide me thanks

Simply change $rsnew to $rs in your code above.