Jump to content


Photo

Need help


  • Please log in to reply
10 replies to this topic

#1 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 02:08 AM

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 !

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 June 2006 - 02:14 AM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 02:16 AM

Hmm I dont get it?

I'm using MySQL. Here's some of the code

$sql = "SELECT * FROM `users` WHERE email='$_POST[email]'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);

if($count == "1") {
           $error[] = '<strong class="error">E-Mail already used by an existing member.</strong>';
           $success = 'show';
        }

$bare_user_query = "UPDATE `users` SET password = '$password', email = '$email', country = '$country' WHERE `nickname` = '$user'";


#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 June 2006 - 02:48 AM

selects the database and counts email.

$sql = "SELECT * FROM `users` WHERE email='$_POST[email]'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);

if there is 1 email thats there tell them off lol

if($count == "1") {
           $error[] = '<strong class="error">E-Mail already used by an existing member.</strong>';
           $success = 'show';
        }

else update the email
$bare_user_query = "UPDATE `users` SET password = '$password', email = '$email', country = '$country' WHERE `nickname` = '$user'";

do the same for password but say sorry please enter a diffrent password ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 02:54 AM

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?


#6 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 05:38 PM

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

#7 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 21 June 2006 - 05:42 PM

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`
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#8 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 06:44 PM

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?

#9 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 21 June 2006 - 07:17 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#10 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 21 June 2006 - 08:59 PM

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.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 June 2006 - 09:10 PM

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 is not what you think it is. The simple way to find out for sure is to actually echo the query and/or structure your sql script like:

$query = " ... whatever it is ...";
$result = mysql_query($query) or die("Error . $mysql_error(). " with query ". $query);
At least then you'll know exactly what the online query is.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users