calmestghost — 2010-02-06T17:51:36-05:00 — #1
I'm using PHP5 and I have a directory where people can submit websites.
Is there a simple built in phpMyAdmin setting to block duplicate submissions?
So, quite simply all that I need to do is have the URL row checked for duplicates and if the URL already exists in the db block the duplicate submission altogether.
I've of course Googled this, however the only promising how-to's assume that you have a lot of back-end knowledge already, which I do not.. I'm a front-end guy.
jeremy_ross — 2010-02-06T18:02:07-05:00 — #2
It would have to be a back-end function to do this.
- query the database and search for the domain name
- if found display error.
Depending on how your form is setup it should be more than a few extra lines of code.
sjh — 2010-02-07T10:32:25-05:00 — #3
Create a unique index on the URL column, and use INSERT IGNORE when inserting data
r937 — 2010-02-07T12:42:03-05:00 — #4
if people can submit urls, and more than one person can submit the same url, do you want to keep track of who first submitted it, or who last submitted it, or how many people submitted it?
or are you only keeping the url itself regardless of who submitted it?
calmestghost — 2010-02-09T00:54:39-05:00 — #5
I think this is probably the best solution. It doesn't matter who submits a URL, the date or anything else. A URL should be submitted once and if accepted, any future duplicate submissions should just be blocked altogether.
So here's what I'm seeing for the URL index:
ALTER TABLE `Listings` ADD INDEX(`URL`)
What exactly should I make that before I click "Go"?
sjh — 2010-02-09T03:04:28-05:00 — #6
calmestghost, that will create an index on the table but not a unique one.
The syntax you're after is CREATE UNIQUE INDEX unique_url ON Listings(URL);
calmestghost — 2010-02-09T05:22:01-05:00 — #7
That's a good solution for now, I'll have to work out a custom error message though. We can call this one solved. Thank you very much for your help everyone.
sjh — 2010-02-09T05:39:35-05:00 — #8
If you're using PHP you can use the mysql_affected_rows function to test whether an insert has been successful or not.