php - Only insert if the value doesn't exist -


+----+----------+-----------+ | id | gamertag | timestamp | +----+----------+-----------+ 

so have table above want insert gamertag if doesn't exist. how that?

$gamertag = "l rah l"; mysql_query("insert `gamertags`(`gamertag`)values ('".$gamertag."')"); 

you should both things: create unique index on column gamertag and use insert ignore.

the unique index prevents duplicate row being added.

the insert ignore prevents mysql issuing warning when duplicate row not added.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -