Also, this will ungracefully kill the script if there was a mistyped emailcode in the input. Killing the script before making any database changes sounds correct, but if you feel like it (this is also not necessary though) you could add error code to gracefully kill it along with a debugging message.