Page 1 of 1

Appending numbers to unique database entries [MySQL]

Posted: Thu May 31, 2007 2:35 pm
by plezops
Using a MySQL database I am adding file names and extensions into the database. There is a problem I am having though. The file names column is set to unique but I would like to use a php script to check if the file name is already there and if so append the next greatest number onto the end so that it will not return an error because a file name is already there. The next time the file was uploaded it would check for the file name, and upon finding both 'test' and 'test1' it would append a 2 to the file name making a 'test2'.

I am just starting with MySQL/PHP together so I don't know very many commands so any in depth explanations would be extremely useful.

Thanks

Posted: Thu May 31, 2007 2:51 pm
by superdezign
I've done that before. It's exactly what your saying..
Just check the database then, if it exists, change the name and check the database for that name, and continue looping through until you have created a name that's safe to insert.