Page 1 of 1

Cancelling query

Posted: Tue May 24, 2005 10:36 pm
by harrisonad
Is there a way to cancel a query operation in mysql. I mean, I want to INSERT a record into database but cancel it if it already exists.

Code: Select all

$query = &quote;INSERT INTO table (field1,field2) VALUES ('val1','val2')&quote;; //if no record with the same field values exists.
ON DUPLICATE KEY UPDATE and IGNORE are not for this situation for it only check if duplicates for unique fields.

Please help.

Posted: Tue May 24, 2005 11:07 pm
by SBro
I think you'll have to do a SELECT query first to see if the values exist, then use a if/else loop to do your subsequent query.

Posted: Wed May 25, 2005 2:46 am
by CoderGoblin
Not sure of correct syntax but I believe you may be able to use the EXISTS keyword.