SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phpMyAdmin - Block Duplicate Submissions

    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.

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Nova Scotia, Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would have to be a back-end function to do this.

    1. query the database and search for the domain name
    2. if found display error.

    Depending on how your form is setup it should be more than a few extra lines of code.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create a unique index on the URL column, and use INSERT IGNORE when inserting data
    Sam Hastings

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SJH View Post
    Create a unique index on the URL column, and use INSERT IGNORE when inserting data
    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:

    Code MySQL:
    ALTER TABLE `Listings` ADD INDEX(`URL`)

    What exactly should I make that before I click "Go"?

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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);
    Sam Hastings

  7. #7
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using PHP you can use the mysql_affected_rows function to test whether an insert has been successful or not.
    Sam Hastings


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •