http://qs321.pair.com?node_id=228307


in reply to Re: Re: MySQL and Duplicate Keys
in thread MySQL and Duplicate Keys

I don't really know much of anything about ON DUPLICATE KEY UPDATE, but I don't think it does what you are hoping for. Even with the duplicate key update in there, your primary key values still have to be unique. What I believe that directive does is allow you to change the existing primary key value to make room for the one you're trying to insert. In your case, you can't change the ISBN number, so you'll either have to check to see if the ISBN number is already entered, or you could simply pass the IGNORE directive with the INSERT. If the ISBN is already entered, then no error will be generated, but the table will not be updated in any way.

Your best bet would be to check the existence of the ISBN and then present the user entering the data with options for selecting which title/author, etc fits the bill the best. So if 2 people issue the same ISBN, but they supply slightly different titles, ask the user to select between their option or the option already in the DB. I'm not sure how well that system would work, but I'm sure you'll come up with something.

One more possible method perhaps: have you thought about supplying the ISBN number to an online book store and retrieving book info from the html? Just an idea...