Forum Moderators: coopster

Message Too Old, No Replies

Preventing multiple insert

trying to prevent multiple submissions on a form to get free samples

         

lubeguy

10:34 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



I currently have a form that collects data from the visitor and puts into a table (we will call this freesample table). This is used to send out free samples of our product.

I also have a seperate table that contains the street address and zip of everybody that has ever requested a free sample(we will call this address table).

I want to make my existing survey form not submit data to the "freesample" table if the address already exists in the "address" table. How do I write the insert command to do this? My guess was:

INSERT INTO freesample (name, street, city, zip) VALUES (%s,%s,%s,%s) WHERE street!='address.street' and zip!='address.zip'

This, obviously, was wrong.

ChadSEO

10:44 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



lubeguy,

Welcome to WebmasterWorld!

You cannot do a query and an insert in the same statement, nor can you do a conditional insert like you were trying. What you would have to do is first query the address table to see if the information is in there, and if not, then do your insert.

Chad

arran

1:05 pm on Aug 26, 2005 (gmt 0)

10+ Year Member



In > 4.0.1 you can use
INSERT INTO IGNORE
which ignores any inserts causing duplicate-key violations. Just make sure the key is chosen correctly and you will have the behaviour you require.

arran.