the best way is to add unique keys to your table. So, depending on what columns need to be unique is what you would put the key on examples:
email, username -- This would require that the email and username be unique.
- firstname.lastname@example.org, kitty is not the same as email@example.com, cat both are unique
- firstname.lastname@example.org, kitty is not the same as email@example.com, kitty both of these are unique
But, if we were to split these into two different unique keys
email -- This would require that only the email be unique
username -- This would require that only the username be unique
Now each one individually needs to be unique, whereas the first example both the email and username needed to be unique. I hope that makes sense.
now when we do our query....
insert ignore into members (email, username) values ('firstname.lastname@example.org', 'kitty');
that will insert into the database UNLESS it isn't unique, then nothing will be inserted.
Or we can do:
insert into members (email, username) values ('email@example.com', 'kitty') on duplicate key update member_count = member_count + 1;
Usually you wouldn't have this on a members table, but to get the example across, if you have a duplicate key, you can update the duplicate row instead of doing an insert.