I see... so you don't want the insert to happen if the code isn't found in the database. Is that correct?
They fill out the form and the code is required? or can they leave it blank?
If they do fill it out, then you want to verify it is valid and not do the insert unless it is. Is that all correct?