I am currently working on a project that allows users to be able to upload movie or book titles, but I'm not sure of the best method to filter out and check if the existing movie title or book already exists. What is the most efficient way in handling this situation?
What is the best way to prevent uploading things with similar titles (movies or books) in PHP/MySQL?
-
how is the data stored? Mysql db? – hackartist Dec 16 '11 at 01:24
-
Yes, it's stored in tables in mysql – diesel Dec 16 '11 at 01:27
-
Some ideas: http://stackoverflow.com/questions/634995/implementation-of-levenshtein-distance-for-mysql-fuzzy-search – Julien Dec 16 '11 at 01:47
4 Answers
If you are going to prevent only the same "titles" to be in a table, just do table search on that column. Using ajax to perform friendly searching for title is good idea which exploit the technique like google search suggestion when typing title. But if you were to prevent the same "content", the better way is to store the digest of the content using like MD5 or so.

- 5,955
- 7
- 48
- 50
i would suggest doing an ajax call to your database to check if the entered title exists. you can do an onchange or blur on the text field to trigger a call to a method to check the database if that name exists and disable the submit button.
i would approach it like this:
- do an onchange or blur to call an ajax method to call a method to check the database to see if that name exists in the database.
- disable the submit button if the name exists, place an error message next to the title field to notify the user it exists in the database already.
i think this should do it, i hope this helps :)

- 1,497
- 10
- 12
-
Thanks! :) But I have never touched AJAX before which might be a problem! – diesel Dec 16 '11 at 01:28
-
look into jQuery.ajax(), it's fairly straight forward here's the [documentation](http://api.jquery.com/jQuery.ajax/) – Robert Van Sant Dec 16 '11 at 02:17
-
-
I still have not figured it out yet but will attempt to use this method ;) – diesel Dec 18 '11 at 22:26
You need to get the input in php, ask if there already exists something with this name in the database and return an error message if it does. Of course if you don't care about telling the user something went wrong you can just put a UNIQUE index on the mysql row for the book/movie name and this will prevent any duplicates. If you also want to prevent similar things... that is a lot harder but look into text processing methods and certain special types of hash functions which can tell you how similar two strings are.

- 5,172
- 4
- 33
- 48
-
The problem is..how is the checking done? Is it a matter of.. using %LIKE% or something like that? – diesel Dec 16 '11 at 01:29
-
you could look for exact copies with = or use like with the % surrounding the value to look for different starts and ends. – hackartist Dec 16 '11 at 01:32
-
-
-
But what if i want to check for similarities? Can I use this function somehow: http://php.net/manual/en/function.levenshtein.php – diesel Dec 16 '11 at 01:37
PHP can do good example of this easy. Here is an example
database name= movies
$sql = mysql_query('SELECT name FROM movies');
$row = mysql_fetch_array($sql);
$name = $row['name']
$uploadname = isset($_POST['name']);
if($uploadname == $name){
echo 'Sorry that movie has been uploaded';//or what ever you want
}else{
echo 'Your movie has been uploaded';//or what ever you want
}
//Use what ever script as long as it can use $_POST
Any questions please ask. P.S. Make sure to secure this $_POST for security reasons don't leave it open to hack just in case you didn't know. This is for all inserting no matter what coding.

- 11
- 1
- 6
-
Hi there! I was originally going to use this method..however I want to find similar tities too. For example: Ocean's 11 vs Oceans 11 and such. I don't want to eliminate the wrong ones. – diesel Dec 16 '11 at 04:06
-
Ok there is a problem there you could remove the ' in all the words for example preg_replace. There is nothing to my knowledge that can do that. PHP, AJAX, JAVASCRIPT, ect.. I am not saying doesn't exist or won't exist. Though a easy way to delete data and see if something similar exists is a search engine for all movies and another separate one for books. You can edit the options so you can look for similarities like that and delete them. If you do this you will want where the admin which is you will be the only one able to access this. Also make report for copies would help too. I did this. – user1079456 Dec 17 '11 at 00:27