gfX Posted June 21, 2006 Share Posted June 21, 2006 Okay, I'm helping a friend out with an Image Hosting script. When a user is logged in, there is a link to an options page, where you can change your password, and e-mail. Well.. Right now, People can change there e-mail in the options page to another persons e-mail that is registered.So, We need the e-mail field to have an error that says if the e-mail is already in use by another member. Well, I did that .. But see what if the user only wants to change their password? The E-mail Box has a value of the users current e-mail .. but if you keep it like that , it gives them an error because that e-mail is already in use by them.So I need help making the user able to change their password only and leave their current e-mail and not get that error. Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/ Share on other sites More sharing options...
AndyB Posted June 21, 2006 Share Posted June 21, 2006 Let's assume you're using some form of database to store this information ... update 'new' email addresses where the email address does not exist in the database anywhere EXCEPT for the user's record. Handle password changes the same way. Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47882 Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 Hmm I dont get it?I'm using MySQL. Here's some of the code[code]$sql = "SELECT * FROM `users` WHERE email='$_POST[email]'";$result = mysql_query($sql);$count=mysql_num_rows($result);[/code][code]if($count == "1") { $error[] = '<strong class="error">E-Mail already used by an existing member.</strong>'; $success = 'show'; }[/code][code]$bare_user_query = "UPDATE `users` SET password = '$password', email = '$email', country = '$country' WHERE `nickname` = '$user'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47883 Share on other sites More sharing options...
redarrow Posted June 21, 2006 Share Posted June 21, 2006 selects the database and counts email.[code]$sql = "SELECT * FROM `users` WHERE email='$_POST[email]'";$result = mysql_query($sql);$count=mysql_num_rows($result);[/code]if there is 1 email thats there tell them off lol[code]if($count == "1") { $error[] = '<strong class="error">E-Mail already used by an existing member.</strong>'; $success = 'show'; }[/code]else update the email[code]$bare_user_query = "UPDATE `users` SET password = '$password', email = '$email', country = '$country' WHERE `nickname` = '$user'";[/code]do the same for password but say sorry please enter a diffrent password ok. Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47891 Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 I know what my code does, That wasn't the question."So I need help making the user able to change their password only and leave their current e-mail and not get that error, that the e-mail is already in use by a member"you know what i mean? Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47894 Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 So is there a way to search teh database to check if the e-mail is already in the database, EXCEPT That users? That's the problem I need to get around.I really really need help here.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48133 Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 A query like this will check for an email that does not belong to a specific user:SELECT user_id FROM users WHERE email = `$email` AND username != `$username`At least I believe != is the right symbol, a quick google check would reveal whether that's true. If not I believe you can just write AND username IS NOT `$username` Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48135 Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 Thank you! That seems to work. ALTHOUGH.Now that I changed the $sql a bit .. my mysql_num_rows will not work and it gives me an error.Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ddgfxco/public_html/imagenerd/options.php on line 11but if I take out the AND username != '$user'"; - it doesn't give me an error. Although I need AND username != '$user'"; for it to work.Anyone know whats up? Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48166 Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 Are you sure that the query is working successfully with the AND username != '$username' because the error makes me think that perhaps you are hitting a MySQL error. If you can confirm that that's not the case, ie you are printing out results from the table or you tried the query directly in phpMyAdmin, then I'm not sure what's up and would need some more information. Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48181 Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 Yeah it works fine with teh AND username != '$username'Though the mysql_num_rows will not work, therefor it will not count succesfully and it won't show if the e-mail is already in use. And when I take out "AND username != '$username' then the mysql_num_rows error goes away though, but you can use someone elses email.It's really weird. Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48225 Share on other sites More sharing options...
AndyB Posted June 21, 2006 Share Posted June 21, 2006 If you're saying the query works fine in phpMyAdmin and the query generates an error in your script, then the query in your script [b]is not what you think it is[/b]. The simple way to find out for sure is to actually echo the query and/or structure your sql script like:[code]$query = " ... whatever it is ...";$result = mysql_query($query) or die("Error . $mysql_error(). " with query ". $query);[/code]At least then you'll know exactly what the online query is. Quote Link to comment https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48228 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.