Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
scr0p
Forum Newbie
Posts: 23 Joined: Mon May 05, 2003 6:49 pm
Location: NY
Post
by scr0p » Sat May 10, 2003 1:06 pm
I am making a sign up form, I want to check if the username exists already, how can I? I pasted a PART of the script below, $name_check retuns a resource ID.. name of table is users, name of field to check is username.
Code: Select all
if(!get_magic_quotes_gpc())
{
$_POSTї'username'] = addslashes($_POSTї'username']);
print $_POSTї'username'];
}
mysql_connect('localhost') or die(mysql_error());
mysql_select_db('SignupTest') or die(mysql_error());
#$name_check = mysql_query("SELECT username FROM users WHERE username = '".$_POSTї'username']."'");
$name_check = mysql_query("SELECT username FROM users WHERE username='scr0p'") or die(mysql_error());
print $name_check;
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Sat May 10, 2003 1:22 pm
You can do something like:
Code: Select all
$name_check = mysql_query("SELECT username FROM users WHERE username='scr0p'") or die(mysql_error());
if (mysql_num_rows($name_check) == 1) {
// username exists
} else {
// username doesn't exist
}
mysql_num_rows():
http://www.php.net/manual/en/function.m ... m-rows.php
Mac