Multiple Loops Producing Slow Script Execution

both <> and != are supported by mysql, but only <> is standard sql

presumably the rows inserted in advance by users have additional data besides what you would produce when generating the 400 possible entries, so ON DUPLICATE KEY would not actually give you any additional fields to update, and IGNORE would make more sense