Trouble with updating tables in h extension

Hi friends.
I have a dialplan like that:

    exten => 5002,1,NoOp()
    exten => 5002,n,AGI(senarios/call.php)
    exten => 5002,n,Hangup()
    exten => h,n,AGI(senarios/update-table.php)

and i wanna after hanging up the current call, update my own table based on the last call information in h extension. My code works correctly but the last call’s information dose not insert into my table and the Information of the last two calls insert in my table. why it happens and how can I fix it?

Give the hangup handler a priority 1 (instead of “n”).

i correct it but my problem dose not fix