lJesterl Posted March 16, 2007 Share Posted March 16, 2007 Im working on a script for users to edit there account here is what im using on the checking to make sure the username or the email doesnt already exist. However its detecting there username and email if they leave it the same. Here is a snippet of code that I am using $status = "OK"; $msg=""; // if userid is less than 3 char then status is not ok if(!isset($alias) or strlen($alias) <3){ $msg=$msg."Userame should be =3 or more than 3 char length<BR>"; $status= "NOTOK";} if(mysql_num_rows(mysql_query("SELECT alias FROM validate WHERE alias = '$alias'"))){ $msg=$msg."Username already exists. Please try another one<BR>"; $status= "NOTOK";} if(mysql_num_rows(mysql_query("SELECT email FROM validate WHERE email = '$email'"))){ $msg=$msg."This Email is already Registered<BR>"; $status= "NOTOK";} if(mysql_num_rows(mysql_query("SELECT alias FROM users WHERE alias = '$alias'"))){ $msg=$msg."Username already exists. Please try another one<BR>"; $status= "NOTOK";} if(mysql_num_rows(mysql_query("SELECT email FROM users WHERE email = '$email'"))){ $msg=$msg."This Email is already Registered<BR>"; $status= "NOTOK";} Link to comment https://forums.phpfreaks.com/topic/42949-editing-account-problem/ Share on other sites More sharing options...
btherl Posted March 16, 2007 Share Posted March 16, 2007 Do you have a unique identifier (like an auto_increment id) for your users? Having that will make it much easier, as you can exclude that row when checking. Link to comment https://forums.phpfreaks.com/topic/42949-editing-account-problem/#findComment-208627 Share on other sites More sharing options...
lJesterl Posted March 16, 2007 Author Share Posted March 16, 2007 yes I do use auto_inc id how would i exclude it? Link to comment https://forums.phpfreaks.com/topic/42949-editing-account-problem/#findComment-208631 Share on other sites More sharing options...
DeathStar Posted March 16, 2007 Share Posted March 16, 2007 And you might want to change the query's. mysql_num_rows(mysql_query("SELECT alias FROM validate WHERE alias = '$alias'")) That is not gonna help the script really.... Never enclose one MySQL function inside another like that. As already explained, a query could return an error and a valid results resource won't exist (or be returned). This would then cause the outer function to fail with a "not a valid MySQL result resource" message Read http://www.phpfreaks.com/forums/index.php/topic,95443.0.html Link to comment https://forums.phpfreaks.com/topic/42949-editing-account-problem/#findComment-208633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.