I had this same problem a little while ago and it took me a bit of playing around to figure it out. I even googled the error and it came back to this exact thread. Here is what I did and what I learned from the process:
You are getting the error because the variable is undefined due to the table being empty in the database, no table = no data = undefined variable.
It had been working perfectly for over a week and then all of a sudden I was getting that error and the table for PTWS in the database was empty.
I changed around the settings to try and get the code to create a new entry with no success.
Deleted the table, deleted the code, reinstalled everything, still didn't work.
In the end, I said I would mess with it at a later time. After letting the server run for a while, it created a new entry in the table by itself and all was well again.
So in conclusion, it seems it sometimes loses its data in the table but in my case, letting the server just do its thing resolved the issue. I managed to export the data it created in the table so in the future if it happens again I can just manually enter the data and avoid the errors.