isedeasy Posted August 12, 2010 Share Posted August 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/210542-duplicate-entry/ Share on other sites More sharing options...
Rohlan Posted August 12, 2010 Share Posted August 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210542-duplicate-entry/#findComment-1098463 Share on other sites More sharing options...
isedeasy Posted August 12, 2010 Author Share Posted August 12, 2010 Cool, exactly what I am looking for Quote Link to comment https://forums.phpfreaks.com/topic/210542-duplicate-entry/#findComment-1098475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.