do not rely on global variables; add check for existing values before using them in sql call