10-18-2008, 03:36 PM
|
#33 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Method of preventing duplicates using IGNORE:
IGNORE will basically stop MySQL returning the error on duplicate entries, therefore you can separate general SQL errors (i.e. syntax errors etc) from duplicate entry errors.
PHP Code:
$sql = 'INSERT IGNORE INTO `upload` (`link`) VALUES (' . $id . ')';
mysql_query($sql) or die(mysql_error());
if(!mysql_affected_rows()) { echo 'Link already exists'; } else { echo 'Your link was added to the database'; }
You need a UNIQUE on the `link` column.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|