Jump to content

Archived

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

gfX

Need help

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 !

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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`

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.