Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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...


In reply to Re^3: MySQL and Duplicate Keys by Coruscate
in thread MySQL and Duplicate Keys by cidaris

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-16 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found