Cancelling query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Cancelling query

Post 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.
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Not sure of correct syntax but I believe you may be able to use the EXISTS keyword.
Post Reply