i have two suggestions for you first, if a
database query doesn't seem to be working, debug it outside of your application language i.e. run your query right in mysql, not via php second, if you want to prevent duplicates, declare a UNIQUE constraint in the database and the database will do the checking for you i.e. you don't have to search first before adding data