473,671 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking for username...

Hi all,

How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?

TIA
Jul 17 '05 #1
18 1759
>How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?


An appropriate way is to insert a row with the username, and it will
fail if the username is in use because of the unique index you have
on the user_name column.

Gordon L. Burditt
Jul 17 '05 #2
*** Domestos wrote/escribió (Mon, 13 Jun 2005 20:50:51 GMT):
How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?


I normally do something like this:

SELECT id FROM users WHERE username='john'

If zero rows are returned, the username is available.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3
Alvaro G Vicario пишет:
*** Domestos wrote/escribió (Mon, 13 Jun 2005 20:50:51 GMT):
How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?

I normally do something like this:

SELECT id FROM users WHERE username='john'

If zero rows are returned, the username is available.

I guess better use not ='john' but like 'john', because of case-sensitive
Jul 17 '05 #4
Domestos wrote:
Hi all,

How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?

TIA


The database can do this by implementing a unique constraint on the column
user_name. After issuing the INSERT, (or any SQL command), check for an
error, and report it. This then solves your general problem of enforcing
data integrity and reporting errors.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec )ure(Dat)a(.com )
Jul 17 '05 #5
Kenneth Downs пишет:
Domestos wrote:

Hi all,

How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?

TIA

The database can do this by implementing a unique constraint on the column
user_name. After issuing the INSERT, (or any SQL command), check for an
error, and report it. This then solves your general problem of enforcing
data integrity and reporting errors.

checking for the SQL error is not a good idea, actually.
Well known programing prupose to use select before insert.
Jul 17 '05 #6
>> The database can do this by implementing a unique constraint on the column
user_name. After issuing the INSERT, (or any SQL command), check for an
error, and report it. This then solves your general problem of enforcing
data integrity and reporting errors.

checking for the SQL error is not a good idea, actually.
Well known programing prupose to use select before insert.


This has the well-known problem that you may find the name not
in use, insert it, and find the name has been taken before you
got to it - unless you've gotten a lock first.

Gordon L. Burditt
Jul 17 '05 #7
Ivan Omelchenko 608308824 wrote:
Kenneth Downs ?????:
Domestos wrote:

Hi all,

How do I check in a mySQL table called 'Users' on column user_name when
registerin g a new user_name to make sure the new 'user_name' does not
already exist in that column?

TIA

The database can do this by implementing a unique constraint on the
column
user_name. After issuing the INSERT, (or any SQL command), check for an
error, and report it. This then solves your general problem of enforcing
data integrity and reporting errors.

checking for the SQL error is not a good idea, actually.
Well known programing prupose to use select before insert.


Well known on what planet?

The Server maintains integrity, that's why they were invented. This
protects the database against a buggy or intentionally misbehaving
application. Not surprisingly, it is also much faster.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec )ure(Dat)a(.com )
Jul 17 '05 #8
*** Gordon Burditt wrote/escribió (Tue, 14 Jun 2005 13:20:31 -0000):
This has the well-known problem that you may find the name not
in use, insert it, and find the name has been taken before you
got to it - unless you've gotten a lock first.


If username field is defined as unique it shouldn't be a great issue. User
will get a generic error rather than a 'user not available' message. Not so
cute but, what's the probability of such a race condition if both queries
(SELECT and INSERT) and consecutive in your code?
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #9
>> This has the well-known problem that you may find the name not
in use, insert it, and find the name has been taken before you
got to it - unless you've gotten a lock first.
If username field is defined as unique it shouldn't be a great issue. User
will get a generic error rather than a 'user not available' message. Not so


That assumes that you CHECK for errors on the insert, which "obviously"
can't happen since you already checked with SELECT, right? Wrong.
If you fail to check for errors on the insert, the user will think
he GOT the username he asked for, and then it won't work (since
presumably the password is different).

Queries ALWAYS take at least two moments and at least one query
from something else can always get in between them unless you've
done something to prevent that (e.g. locking, or ensuring that only
one client exists at a time).

Oh, yes, there's no reason why you have to give a "generic error"
if the insert fails, except, of course, for Bad Web Design(tm).
cute but, what's the probability of such a race condition if both queries
(SELECT and INSERT) and consecutive in your code?


If your site is popular enough, and lasts long enough, it's near
100% to happen eventually. And it will probably happen right when
your prospective client is about to decide to let you design his
web site at a generous rate, or when he's about to approve your
final check. Murphy's Law can be quite nasty.

The fact that you ask such a question means I don't want you any
where near the software design for airplanes, nuclear reactors, air
traffic control systems, weapons systems, automobile on-board
software, or cellular phone firmware. I don't really want you
around the design of any web sites I use to buy stuff, either.

Gordon L. Burditt
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2639
by: Philip D Heady | last post by:
Hi, I'm validating a simple form for input via post ($PHP_SELF). Near the end I check for username and password. I'm using simple if, elseif, else statements. I require them to enter password twice and check that they match. Problem is script doesn't valide past username input and I dont know why!! If you don't enter a password it doesn't do the validation anymore, it just dies for some reason. I would greatly appreciate anyones help,...
7
2158
by: Sharon | last post by:
Hi, Is it possible to check parameters against other parameters, as in: <xsl:variable name="tableData"> <xsl:apply-templates select="general/data/rows/row/fvalues" mode="tableData" /> </xsl:variable> (The parts I'm referring to are in capitals). Because this gives me no
14
3197
by: student_steve | last post by:
Hey guys, here is some code for a password security measure in a website: <?php session_start(); $errorMessage = ''; if (isset($_POST) && isset($_POST)) { if ($_POST === 'steven' && $_POST === 'crocker') { $_SESSION = true;
3
1441
by: Barkster | last post by:
I registered for this service and when I put my username it looked up the username without submitting and told me it was taken after leaving the field. Any ideas on how they are doing it http://forums.oscommerce.com/index.php?act=Reg&CODE=00 use username: barkster to test Thanks
1
4749
by: sankviju | last post by:
Here i created a javascript+php code by which u can create a check available link that u will usually see in many websites.Without submitting the whole form just u can check wther a username exist in the database or not =================================================-===== 1:filenames: index.php write a javascript fn like this in the head tag <script language="javascript"> function x() { var y=document.form1.t.value; ...
1
1562
by: lintolawrance | last post by:
hi friends, can any one out here help me by giving the guidelines for checking the username availability at run time with the help of Ajax.
2
1745
by: momogi | last post by:
Hi theScripts! I have a problem with my session. When user login in my site, the session will save the user name and password. In my Login.php I have: session_start(); $qr="SELECT*FROM tbllogin WHERE nama='$_POST' AND password='$_POST' "; $res=mysql_query($qr); $row=mysql_fetch_assoc($res); $num=mysql_num_rows($hasil);
14
3623
Markus
by: Markus | last post by:
Making a basic validation script, i hit a snag. If user was to input say " "(minus quotes), into the textfield and then submit it the length check i have used would return it as true and therefore execute the rest of the code. Is there a way to compensate for spaces, as to include them in the length? Or do you have a different idea? The code:
1
2003
by: geetamadhavi | last post by:
Hi All, I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i even tried with echo also how to solve this the message should come under in the same window only see my code it is program ---- <?php // Connects to your Database mysql_connect('localhost', 'root', 'epara') or die(mysql_error());
0
8472
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.