/    Sign up×
Community /Pin to ProfileBookmark

Newbie Question

I have a user registration form and I know how to submit the data to MySQL but before the data gets submitted I want to check and see if the username they entered is already taken. I can do this in asp/vbscript but I’m lost here.

$USERNAME = $_POST[‘username’]

$_SQL = “SELECT USER_NAME FROM MEMBERS WHERE USER_NAME='” & $USERNAME & “;”

If EOF Then
*//Code if username not taken
Else
*
//Code if username is taken
End if

This is very generic so you get an idea of what I’m looking for. Can anyone help?? ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehApr 18.2006 — [code=php]<?php

#assume DB connect here

$query = "SELECT USER_NAME FROM MEMBERS WHERE USER_NAME='" . $USERNAME . "'";
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
# username in use
}
else
{
# username not in use
}

?>[/code]
Don't forget your variable names, column names and table names are case sensitive! Are you sure MEMBERS , USER_NAME and $USERNAME are upper case?
Copy linkTweet thisAlerts:
@tready29483authorApr 18.2006 — That is great thnx. if I have anymore questions I'll come back here.
×

Success!

Help @tready29483 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...