View Single Post
Old 10-18-2008, 03:36 PM   #33 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
codefreek (10-18-2008)