rough first pass at fixing double quote issues and use of backticks. also moved MySQL credentials inside the script to at least get them off the command line.