Skip to content
Advertisement

MySQL INSERT IGNORE INTO keeps adding duplicate entries

Here’s the particular area im having an issue with

mysql_query("INSERT IGNORE INTO storeip (ip)
VALUES ('$ip')");

when testing this it keeps adding the same entry to the table even though I have set IGNORE INTO.

Advertisement

Answer

It looks like you don’t have a UNIQUE INDEX on the IP column. In order for INSERT IGNORE to work as required, that’s neccessary. Try this;

ALTER TABLE ip ADD UNIQUE(ip)

To remove duplicates already, you can run this.

ALTER IGNORE TABLE ip ADD UNIQUE(ip)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement