Using PHP, you can't efficiently prevent this. You would have to query the database and to check to see if it currently exists. Even then, this isn't the best way because under high load, a record can sneak in.
The only way to ensure that a duplicate isn't inserted in the database is by marking database fields as unique, or in MySQLs case, by applying unique indexes across individual or multiple fields..
Some databases support conditional inserts or update/inserts, but this is a pretty advanced feature and not found in mysql.