Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2006, 7:24 PM   #1
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
MySQL Checking Help

ok I got it working and everything. Now i'm getting a problem. Ok I created a user and all and it gets put in the table. Then I test out the checking and if says Email is been sent but I just added the same user again

heres the code
[php]
$user_check_sql = mysql_query("SELECT username FROM user WHERE username='$username'") or die(mysql_error());
$email_check_sql = mysql_query("SELECT email_address FROM user WHERE email_address='$email'") or die(mysql_error());

$user_check = !mysql_fetch_row($user_check_sql);
$email_check = !mysql_fetch_row($email_check_sql);

if($user_check){
print("That Username is already takin' please select a new username<br>\n");
}else{
if($email_check){
print("E-Mail is already in use please use a different email<br>\n");
}else{
$q = mysql_query("INSERT INTO user (username, password, email_address, city, state, country, gender, month, day, year)
VALUES('$username', '$password', '$email', '$city', '$state', '$country', '$gender', '$month', '$day', '$year')");
}
}
[/php]
KyrinComaBlack is offline   Reply With Quote
Old Jan 28th, 2006, 7:31 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Huh?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 28th, 2006, 7:36 PM   #3
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
Quote:
Originally Posted by DaWei
Huh?
Ok what I am doing is. Okay the user registers into the database for login etc. And lets say another user comes along and trys to register and either trys to use the same user or email as that one did. And this is where the problem comes along. I create a test user. And I got no problems it registers and is entered into the database. Now heres the problem. I went to check out the verification of the user/email lookup and when I enter the same user in there. I get no errors saying the user/email name matches the data in the database and it gives me this. "Validation email has been sent". Basically its telling me that the user i enter before isn't there when it is.

Sorry for the confuseion
KyrinComaBlack is offline   Reply With Quote
Old Jan 28th, 2006, 9:10 PM   #4
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
Your if statements are always going to be vaild because even if the query doesn't retun a row it does return some info that makes the varible non-null.

Use

if(mysql_num_rows($user_check)) != 0)

instead of

if($usercheck)

Not sure that works the way you think it does.

And why exaclty do you have !mysql_fetch_row? Never seen the use of a ! like that.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Jan 28th, 2006, 10:49 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
For your own edification, you should also check the PHP manual for the practical difference between == and ===.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 29th, 2006, 12:06 AM   #6
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
nope it still does the samething
KyrinComaBlack is offline   Reply With Quote
Old Jan 29th, 2006, 8:34 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
As BlazingWolf says, your construct, !mysql_fetch_row, may be problematic. The ! operator returns TRUE if the operand is not TRUE. There are many values that are neither TRUE nor FALSE. Implicit conversions handle many of them properly (resulting in the values 1 or 0), but I think you're courting a problem. It's the same problem one can get into by using "== FALSE" instead of "=== FALSE." I suggest that you test the return value directly rather than manipulate it with the ! operator first. This is not C; PHP has a boolean type.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 29th, 2006, 7:27 PM   #8
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
ok i figured it out

[php]
$user_check_sql = mysql_query("SELECT username
FROM user
WHERE username='$username'");
$email_check_sql = mysql_query("SELECT email_address
FROM user
WHERE email_address='$email'");

$user_check = mysql_fetch_row($user_check_sql);
$email_check = mysql_fetch_row($email_check_sql);

if($user_check > 0){
print("<font color=\"#FF0000\">That username is already takin' please select a new username!</font><br>\n");
}else{
if($email_check > 0){
print("<font color=\"#FF0000\">E-Mail is already in use please use a different email!</font><br>\n");
}else{
$q = mysql_query("INSERT INTO user (username, password, email_address, city, state, country, gender, month, day, year)
VALUES('$username', '$password', '$email', '$city', '$state', '$country', '$gender', '$month', '$day', '$year')");
}
}
[/php]
KyrinComaBlack is offline   Reply With Quote
Old Jan 30th, 2006, 7:13 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Glad you figured it out .
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC