Selecting the latest value that user just entered

Hello!

May I know how do we get the value that user entered the last right after submitting the form? Assuming the last value user entered is “Abby” and second last is “Bella”.

I’m trying to get the value Abby as it is the last value that being submitted to the system, but using the following SQL statement I can only get the result as Bella.

The following is the example:
$sql=“SELECT cust_name FROM customer ORDER BY id DESC LIMIT 1;”;

I also tried to put the codes in onValidate, onAfterInsert, onBeforeInsert and others too, but the result is either blank or still the second last result.

Please advice where is the mistake…

Thank you!

why not just use code to set [LastName] each time a name is entered? I am not understanding why you are using SQL