logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-16-2012, 02:01 PM   #1
richclare1991
 
Join Date: Apr 2012
Posts: 4
Default Username check

Hi guys, trying to work on a username check so if when filling out the registration form the username is already taken by a user already registered it will echo out a error and stop the process. Ive got other checks working fine on the form just this one im struggling with. Here is the code i am trying
$namecheck = mysql_query("SELECT username FROM members WHERE username = '$username'");
$count = mysql_num_rows($namecheck);
if ($count!=0)
{
echo "Username is already taken please try again!";
}
else

When i run the code the registration page and enter a username that is already taken or that is not taken i get the error -

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in blablabla

Any help appreciated
richclare1991 is offline   Reply With Quote
Old 04-17-2012, 01:42 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

this works
Code:
<?php $namecheck = 0;  // try other numbers
$count =$namecheck;
if ($count>0)
{
echo "Username is already taken please try again!";
}
?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-17-2012, 12:10 PM   #3
richclare1991
 
Join Date: Apr 2012
Posts: 4
Default

sorry mate i dont understand, where would i place the query?
thanks for replying
richclare1991 is offline   Reply With Quote
Old 04-17-2012, 12:27 PM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

if the num rows is returning correctly try

$namecheck = mysql_query("SELECT username FROM members WHERE username = '$username'");
$count = mysql_num_rows($namecheck);
if($count>0)
{
echo "Username is already taken please try again!";
}
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com