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
https://forums.phpfreaks.com/topic/210542-duplicate-entry/
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
https://forums.phpfreaks.com/topic/210542-duplicate-entry/#findComment-1098463
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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