Jump to content

Recommended Posts

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 !
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47883
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-47891
Share on other sites

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`
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48135
Share on other sites

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 11

but 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?
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48166
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48181
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48225
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12503-need-help/#findComment-48228
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.