If your using mysql
-set a primary key in the database
-using insert......on duplicate key update .....

see MySQL :: MySQL 5.0 Reference Manual :: 12.2.5.3 INSERT ... ON DUPLICATE KEY UPDATE...