ngreenwood6 Posted August 5, 2008 Share Posted August 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/ Share on other sites More sharing options...
Jabop Posted August 5, 2008 Share Posted August 5, 2008 Looks good Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608930 Share on other sites More sharing options...
xstevey_bx Posted August 5, 2008 Share Posted August 5, 2008 Have you ran a mysql query to try and detect the username from the database? $query = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($query); $num = mysql_num_rows($result); Then try If ($num > 0 && ..... Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608931 Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 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 } Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608933 Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2008 Author Share Posted August 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608937 Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2008 Author Share Posted August 5, 2008 Can anyone help me out with this it would be very helpful for future coding? Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608971 Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608984 Share on other sites More sharing options...
tmallen Posted August 5, 2008 Share Posted August 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/118327-formatting-if/#findComment-608989 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.