You have a much bigger problem: your code is left open to SQL injection attacks.
Never ever build SQL queries by concatenating with user-input strings.
Better use
parameterized queries instead.
Parameterized queries in PHP with MySQL connection[
^]
For your issue, I don't see where you persist $atmp variable between page calls. Your php script is executed at every page load, so a local variable will not retain its previous value and will be initialized the same way everytime.
I'm not a PHP specialist, but one thing I can see is that you load $atmp value from hidden field in request, but you never set this field back when the value changes. At each page load, your script gets the same value.
Variable persistence in PHP[
^]