![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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] |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 | |
|
Programmer
|
Quote:
Sorry for the confuseion ![]() |
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Programmer
|
nope it still does the samething
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Programmer
|
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] |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|