manhattes Posted February 22, 2016 Share Posted February 22, 2016 I am reading an RSS feed and sometimes I pull in duplicates of data. $citable= "INSERT INTO TableName (Company, Form, Date, Link) VALUES ('" . $FnumI ."',' " . $Form ."','" . $msqldate ."','" . $Flink ."') ON DUPLICATE KEY UPDATE Company='" . $FnumI ."', Form='" . $Form ."', Date='" . $msqldate ."', Link='" . $Flink ."'"; Is there a way I can only record the data if Link does not exist? Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/ Share on other sites More sharing options...
Jacques1 Posted February 22, 2016 Share Posted February 22, 2016 Do not create duplicate topics (how ironic). Your thread is here: Deleting Duplicate Error Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531352 Share on other sites More sharing options...
ginerjm Posted February 22, 2016 Share Posted February 22, 2016 Do a query for 'link' before you try the insert? PS - you can simplify your current syntax with this: $citable = "insert into TableName (Company, Form ,Date, Link) values('$fnumI', '$form', '$msqldate', '$Flink'); Plus - I believe that 'Date' is a reserved word. Try re-naming that column to make your future use of this table less problematic. Also - you should be sanitizing these inputs. Try using a prepared query instead of this method. Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531353 Share on other sites More sharing options...
manhattes Posted February 22, 2016 Author Share Posted February 22, 2016 Do not create duplicate topics (how ironic). Your thread is here: Deleting Duplicate Error sorry that issue was solved and it led to this question. wasn't sure of protocol. Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531354 Share on other sites More sharing options...
manhattes Posted February 22, 2016 Author Share Posted February 22, 2016 What do you mean do a query for link? How can I do the query for an incoming link before its in the table? Do a query for 'link' before you try the insert?PS - you can simplify your current syntax with this:$citable = "insert into TableName (Company, Form ,Date, Link)values('$fnumI', '$form', '$msqldate', '$Flink');Plus - I believe that 'Date' is a reserved word. Try re-naming that column to make your future use of this table less problematic.Also - you should be sanitizing these inputs. Try using a prepared query instead of this method. Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531355 Share on other sites More sharing options...
ginerjm Posted February 22, 2016 Share Posted February 22, 2016 You asked: Is there a way I can only record the data if Link does not exist? My answer means - do a query to SEE if the Link already exists before you try and insert it. Is that not clear? Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531356 Share on other sites More sharing options...
Solution manhattes Posted February 23, 2016 Author Solution Share Posted February 23, 2016 Do not create duplicate topics (how ironic). Your thread is here: Deleting Duplicate Error Jacques1 Advanced Member 1,770 posts Posted Yesterday, 10:23 PM INSERT IGNORE with Link being a primary or unique key. Like This Best Answer Quote MultiQuote Thanks. Changed the row value to primary. Quote Link to comment https://forums.phpfreaks.com/topic/300861-preventing-duplicates/#findComment-1531375 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.