Jump to content

Duplicate Entry


isedeasy

Recommended Posts

I want to track clicks via IP so I have a table with 'ID' and 'IP' combined to make the tables unique key.

 

I can see two methods of inserting data, 1 Requires 1 query the other 2.

 

option 1 - check to see if a row exists, if not then insert into table

 

option 2 - just insert the row and if its a duplicate it will not be added to the table.

 

Would option 2 work and would it be considered good practise?

Link to comment
Share on other sites

I recently ran into something similar. I found this SQL Command:

 

INSERT IGNORE INTO `table`
SET `ID` = $user_id,`IP` = $user_ip;

 

Basically it will insert the value unless it is already there, and if it IS there... it will simply ignore it and no errors will be outputed.

 

A life saver...

 

More info here:

 

http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.