CoderZone.org

Category: >> mySQL >> Check for duplicates and delete duplicates from database. Bookmark and Share

<< lastnext >>

Snippet Name: Check for duplicates and delete duplicates from database.

Description: Before a user submits data to mysql, check for and remove duplicate entries before the data is entered into the database.

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PLSQL
Last Modified: March 16th, 2009

$check = mysql_query("SELECT * FROM `table` WHERE `field` = '$value'");
 
IF (mysql_num_rows($check) > 0){
     // Duplicate EXISTS. Remove it
     mysql_query("DELETE FROM `table` WHERE `field` = '$value' LIMIT 1");
}
 
// INSERT NEW data
mysql_query("INSERT INTO `table` (`field1`) VALUES ('$value1')");  
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 6