Jump to content

[SOLVED] Need help with an IF statement


NevadaSam

Recommended Posts

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

;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.