/    Sign up×
Community /Pin to ProfileBookmark

checking if the login is unique

I am creating a website with registration and stuff.
Came to a problem that it is possible someone may try to register with the same login or with the same email that someone used before. So checking is necessary. Thought of doing this:

[code=php]$check_login=dbGetData(“select id from artist where login=$login”);
$check_email=dbGetData(“select id from artist where login=$email”);[/code]

But then thought that if there are A LOT of users, this query might be very-very slow as email and login fields are not indexed and I am not sure it is a good solution to do so.

Am I on the right track? How would you tackle this problem?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@andre4s_yMay 26.2008 — Maybe :

Create UNIQUE Index in your database..
Copy linkTweet thisAlerts:
@Louigi_VeronaauthorMay 26.2008 — when a person logs in, you search the db by login, not id... hm. I further wonder if big tables should have logins and pass fields indexed. I mean in a table of 100000 users how fast will a login pass query operate?
Copy linkTweet thisAlerts:
@NogDogMay 26.2008 — If the fields are indexed, it will run quite quickly. Presumably login should be unique, so it would have a unique index assigned, while password would just be a regular (non-unique) index. If you do not want to allow duplicate emails, the email column would also have a unique index on it.

You can then check for duplicates when inserting new records by simply doing the insert query, and if it fails, check to see if it's a duplicate key error. (In MySQL, check to see if mysql_errno() == 1062.)
Copy linkTweet thisAlerts:
@Louigi_VeronaauthorMay 26.2008 — But I've heard that indexing field really increases the size of db. Is it true?
Copy linkTweet thisAlerts:
@NogDogMay 27.2008 — But I've heard that indexing field really increases the size of db. Is it true?[/QUOTE]
Depends on how you define "really", I guess. Sure, it adds some more data that needs to be stored on the disk, but I don't think I've ever heard of anyone not using an index because of however much it adds. The only issue I've heard of with indexes is that while they speed up data retrieval, they can slow down data inserts (since there is additional index data to be saved along with the actual data). But again, I can't recall hearing of an actual situation where an index was not used because of that. The only concern should be to not just index [i]everything[/i], but only those columns where it will actually help optimize the select queries.
×

Success!

Help @Louigi_Verona spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...