JackTheJack
JackTheJack

Reputation: 187

Add unique value only

I have tried using the following code to try and only enter a unique domain in the database.

$query = "INSERT IGNORE INTO domains2 (domain)
values ('$query2')";
print "running query: <br/>\n$query<br/>\n";
mysql_query($query, $link)
or die ("INSERT error:" .mysql_error());

For example if it tries to enter test.com/test.php and its already in the table it wont do it. However It still adds the data onto the table.

Upvotes: 0

Views: 148

Answers (1)

ceejayoz
ceejayoz

Reputation: 180147

You have to have a UNIQUE key on the domain field for this to work.

Upvotes: 2

Related Questions