Prevent Duplicate entries...

Discussion in 'PHP' started by Jen2swt, Oct 28, 2009.

  1. #1
    Hi
    I created an image generator where a user enters a name and it spits/creates an image for them. I then have those images saved using the name entered on the server.

    Question is how can I prevent someone else coming along and creating the same name? I want it to display a message stating that name was already created.

    Would I create an IF statement?
     
    Jen2swt, Oct 28, 2009 IP
  2. adwebtiser

    adwebtiser Peon

    Messages:
    95
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes you would need an if statement

    if you are recording these image names on any table on database, then its pretty simple just run a query on that table which would check if that name already exists or not if it returns with records in database then it should write a error message!

    simple
     
    adwebtiser, Oct 28, 2009 IP
  3. Jen2swt

    Jen2swt Active Member

    Messages:
    217
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    They are not saved in a DB, just saved to a directory on the server.

    This is what I'm using:

    $upload = $_FILES['image']['tmp_name'];
    $name = $_POST[name];
    $text = str_replace (" ", "-", $_POST[name]);
     
    Jen2swt, Oct 28, 2009 IP
  4. adwebtiser

    adwebtiser Peon

    Messages:
    95
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So you have no record of the users on your site?
     
    adwebtiser, Oct 28, 2009 IP
  5. Jen2swt

    Jen2swt Active Member

    Messages:
    217
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    No just the images it generates saved to a directory...

    They are all named accordingy to what they enter. So if they enter jen2swt, it saves the image as jen2swt.png in the directory.
     
    Jen2swt, Oct 28, 2009 IP
  6. adwebtiser

    adwebtiser Peon

    Messages:
    95
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    so what use would that image do when it cant relate to anything? =/

    then I would make a record of it in a table that would be the easiest way. or right a script which would search for the file

    or whatever script you are using for uploading the image to the directory, ask it to check if the file already exists or not if so abort the uploading process and write the error message
     
    adwebtiser, Oct 28, 2009 IP
  7. Jen2swt

    Jen2swt Active Member

    Messages:
    217
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #7
    I guess that's what I need help with. Writing something that will check the directory for duplicate names and write an error message that it already exsists if someone is uploading the same name...I'll search some more.

    Thanks for all the help :)
     
    Jen2swt, Oct 28, 2009 IP