当前位置: 动力学知识库 > 问答 > 编程问答 >

php - 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. Iv'e only just started learning PHP & mysql so any help would be appreciated.

Thanks

网友答案:

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)

网友答案:

Why shouldn't it? ignore just ignores errors. Make the ip unique.

alter table storip add unique (ip);
网友答案:

If the IP is the only field on the table, just make it primary key and there will be no duplicates

alter table storeip add primary key (ip);
分享给朋友:
您可能感兴趣的文章:
随机阅读: