prw Posted February 19, 2011 Share Posted February 19, 2011 Hello - I've come to an issue with something I'm working on and have searched around with no luck. When editing user accounts I want it to not be able to change the e-mail address into existing ones on other rows, but when submitting the form it takes into account that this particular rows email address is the same as the one which was sent via $_POST and throws up the error. The desired behaviour I want is for it to ignore the ID of the row which was posted, but take into account every other row. Here's the code as it stands at the moment: $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); } if (mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); } Link to comment https://forums.phpfreaks.com/topic/228160-ignore-current-id-when-checking-current-email-address/ Share on other sites More sharing options...
PaulRyan Posted February 19, 2011 Share Posted February 19, 2011 $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email' AND username!='$loggedUsername' LIMIT 1"); if(mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); } Just make sure that you don't include the current user by filtering them out, use something like the above. Tell me if this works or not buddy Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/228160-ignore-current-id-when-checking-current-email-address/#findComment-1176597 Share on other sites More sharing options...
prw Posted February 19, 2011 Author Share Posted February 19, 2011 Ah perfect, I never thought of doing it like that. This is what I used instead: $checkemail = mysql_query("SELECT email FROM users WHERE email='$email' AND id!='$id' LIMIT 1"); Thanks! Link to comment https://forums.phpfreaks.com/topic/228160-ignore-current-id-when-checking-current-email-address/#findComment-1176598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.