NevadaSam Posted December 8, 2007 Share Posted December 8, 2007 When a person registers an unique userID will always identify them so if they want to they can change their login name as long as that login name is not being used by someone else. So when a person enters a login name either as a new member or they are changing their current login name during an update, the script needs to know if it should check the user table. Please help me say this: if POST-name is not equal to current-name // (Ex: member changing their name) or current-name does not exist // (Ex: new member) if ($_POST['login'] != !empty($_SESSION['currentLogin']) || empty($_SESSION['currentLogin'])) { // Check to see if login name exist. I can do this. I just need help with the IF statement. } Sam ; Quote Link to comment Share on other sites More sharing options...
atlanta Posted December 8, 2007 Share Posted December 8, 2007 You would want to do if ($_POST['login'] != $_SESSION['currentLogin'] || $_POST['login'] != $_SESSION['currentLogin'] { Execute here try that } Quote Link to comment Share on other sites More sharing options...
NevadaSam Posted December 8, 2007 Author Share Posted December 8, 2007 if ($_POST['login'] != $_SESSION['currentLogin'] || $_POST['login'] != $_SESSION['currentLogin'] ) { Execute here try that } That just says the same thing twice. Did you mean something else? And in the case of a new member there would not be a currentLogin and that would cause an error. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 8, 2007 Share Posted December 8, 2007 it should always check the name for duplicate usersnames and report back a count of the matchign rows if its greater than 0 don't allow this user name Quote Link to comment Share on other sites More sharing options...
NevadaSam Posted December 8, 2007 Author Share Posted December 8, 2007 cooldude832, I am not having a problem with MySQL statements. I need to word the if statement so the script will know to check the table or not. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 8, 2007 Share Posted December 8, 2007 and I am saying who cares if it needs to, you are only checking aganist the previous username not the rest of the set of used usernames, so why waste that time of checking it in the first place. Check the pool and be done <?php $user = mysql_real_escape_string(strip_tags(trim($_POST['Username']))); $q = "Select count(*) from `Table` Where Username = '".$user."' and UserID != ""$_SESSION['UserID']."'"; $r = mysql_query($q) or die(mysql_error()); if(mysql_result($r,0)>0){ //The user name is in use by another user } else{ //Its their current username or a new one so go ahead and update that field ?> That is all you need I use it and it works every time Quote Link to comment Share on other sites More sharing options...
NevadaSam Posted December 8, 2007 Author Share Posted December 8, 2007 I appreciate your replies, but I currently have a query and all necessary MySQL commands to compare the input against information in the table. I am not asking for help with that. I wish to update my script. If the person is not changing their login name then it is not necessary to access the MySQL server or table to make a comparison. I need help with an IF statement to say this: if POST-name is not equal to current-name // (Ex: member changing their name) or current-name does not exist // (Ex: new member) Sam ; Quote Link to comment Share on other sites More sharing options...
NevadaSam Posted December 8, 2007 Author Share Posted December 8, 2007 OK, I finally figured out how to write this. Here is what works: if ((!empty($_SESSION['currentLogin']) && $_POST['Login'] != $_SESSION['currentLogin']) || empty($_SESSION['currentLogin'])) { ...check input against user table... } I appreciate your replies and I am sorry I did not explain my self well. Problem Solved! Thanks, Samantha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.