Jump to content

formatting if


ngreenwood6

Recommended Posts

I have a statement that i am trying to figure out how to write out. I want it to check that the username isn't in the database ($username > 0) and that it isnt the same as it is now (!= $oldusername) . This is what I have come up with.

 


if ($username > 0 && $username != $oldusername)
{
do this
}

 

Is that correct because it is not going past that point if the username is the same.

Link to comment
https://forums.phpfreaks.com/topic/118327-formatting-if/
Share on other sites

loose example:

 

$currentusername = "Johnny";
$newusername = $_POST['newusername'];
$sql = "select username from table where username = '$newusername'";
$result = mysql_query($sql);
$found = mysql_num_rows($result);
if (($found > 0) && ($newusername != $currentusername)) {
 // good to go, do something
} else {
 // already exists are is same as old, do something
}

Link to comment
https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608933
Share on other sites

crayon violent thanks for the example. However, i am trying to allow the user to update their profile. the problem that I am running into is that I can check the database for the email, but if the user decides to keep it the same it gives them the error that email is already there. I want it to not check the database if they keep it the same. How would i go about doing that?

Link to comment
https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608937
Share on other sites

what are you wanting help with? If you don't want it to check the database if the user posts the same thing, then just check if it's the same thing and not query the database if it's the same as the current.

 

if ($oldusername != $newusername) {

  // query database

}

 

I mean, is that what you're asking, or something else?

Link to comment
https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608984
Share on other sites

Sounds simple enough. If a user is changing their info, obviously you don't throw an error when the new email is the same as the old one, only if it's the same as another user's. A new user would perform the same check, except there'd be no need to see if their new email is the same as a former address, as they're a new user.

Link to comment
https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608989
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.