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
harrisonad
Forum Contributor
Posts: 288 Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:
Post
by harrisonad » Tue May 24, 2005 10:36 pm
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 = "e;INSERT INTO table (field1,field2) VALUES ('val1','val2')"e;; //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 » Tue May 24, 2005 11:07 pm
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.
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Wed May 25, 2005 2:46 am
Not sure of correct syntax but I believe you may be able to use the EXISTS keyword.