Jump to content

MySQL unique key error


The Little Guy

Recommended Posts

I have a mysql unique index on two columns:

UNIQUE KEY `page_id` (`page_id`,`tag_id`)

 

I have a mysql query like this:

mysql_query("insert into link_tags (page_id, tag_id) values ($page_id, $tag_id)");

 

If I run that, what would be the best way for php not to fail if the key already exists?

 

within a while loop, would this be best?

if(mysql_query("insert into link_tags (page_id, tag_id) values ($page_id, $tag_id)"))
continue;

 

Or would the code above (first code) be sufficient enough?

Link to comment
https://forums.phpfreaks.com/topic/237133-mysql-unique-key-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.