use JS error handling instead of complex SQL query to control duplicates