+----+----------+-----------+
| id | gamertag | timestamp |
+----+----------+-----------+
So I have the table above I want to only insert a gamertag if it doesn't already exist. How could I do that?
$gamertag = "l RaH l";
mysql_query("INSERT INTO `gamertags`(`gamertag`)VALUES ('".$gamertag."')");
You should do both things: Create a unique index on column gamertag and use insert ignore.
The unique index prevents a duplicate row from being added.
The insert ignore prevents mysql from issuing a warning when the duplicate row is not added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With