EMail address changes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

EMail address changes

Post by 4Boredom »

I have a page that allows users to change their email address, gender, and birthdate all on one page

I do not want users to be able to change to an email address that is already in the database... but I want them to be able to click update and keep their current email address with no errors, any ideas?

Code: Select all

$check_email = @mysql_query("SELECT email_address FROM users WHERE email_address= '{$email_address}' ");
if(mysql_num_rows($check_email)>0){
	 echo "Please fix the following errors: <br />"; 
     echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />"; 
	 unset($email_address); 
	exit;
}
I also have a check for email current above this I just donno how to manipulate them to work togetherbut this may help?

Code: Select all

$email_current = @mysql_query("SELECT email_address FROM users WHERE username= '{$username}' ");
$current = mysql_fetch_array($email_current);
if($current['email_address']==$email_address){
	 echo "The Email Address you entered is the same as your current one.<br />"; 
	 exit();
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Make the column unique and you won't be able to update the record to an existing one.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Or you can select and check. If the number of rows returned on the check is 0 then that email does not exist and proceed. Else, error out without doing anything.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

4Boredom where did you learn to do that?:

Code: Select all

@mysql_query("SELECT email_
Really not a good idea, try checking for errors instead of suppressing them. If you need error supression for production error_reporting(0) is your friend.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

i dont have trouble with error reporting.. i am asking what would be the best way to combine those two codes to make it work
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Here at dev net we don't write solutions for you. Instead we help you with any problems you might be having. Since you haven't actually defined a problem we can't help you. We have however highlighted a possible area for improvement which make it possible for you to fix the problem yourself.

What I'm saying is: Modify your code with the improvements suggested and play about for a while. If you still have problems repost your code and come back and I'll gladly help you out some more.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

say if I am derek@4boredom.com and I wanna change my birthdate and i click update.... it will come up as email already in the db.. I want the check to search the db for all name EXPECT the users own.... how do i do that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

...WHERE `userid` != '$me'
Where $me is their user ID.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

When I hit update and do not change the users current email... (there are 3 fields, I want them to be able to change whatever they want but just from one page)


Please fix the following errors:
Your email address has already been used by another member in our database. Please use a different email address!

Code: Select all

$sql_email_check = mysql_query("SELECT username FROM users WHERE email_address='$email_address'");
$email_check = mysql_num_rows($sql_email_check);
$check = mysql_fetch_array($sql_email_check);
if($check['user']!=$username){
echo "Please fix the following errors: <br />"; 
echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />"; 
unset($email_address); 
exit(); }
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you inserting or updating? And what is triggering that message.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Why not just let there be multiples of the same email address? It may even be better that way, otherwise someone could type in an email address and find out who else is a member, could be a privacy concern...
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

the email address is used to login

I allow users to change their username to whatever they want... such as their first name

and to the update or insert question...

Code: Select all

# Enter info into the Database. 


$sql = mysql_query("UPDATE `users` SET 
                email_address = '{$email_address}' WHERE username = '{$username}' ");


                $sql = mysql_query("INSERT INTO `basic` 
                (`gender`, `month`, `day`, `year`) VALUES 
                ('" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')"); 

		if(!$sql){ 
    echo 'There has been an error creating your account. Please contact the webmaster.'; 
    echo mysql_error();
} else { 
    echo 'E-Mail updated! This is your new login, so remember it! '.$email_address.''; 
}
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

4Boredom wrote:the email address is used to login

I allow users to change their username to whatever they want... such as their first name

and to the update or insert question...

Code: Select all

# Enter info into the Database. 


$sql = mysql_query("UPDATE `users` SET 
                email_address = '{$email_address}' WHERE username = '{$username}' ");


                $sql = mysql_query("INSERT INTO `basic` 
                (`gender`, `month`, `day`, `year`) VALUES 
                ('" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')"); 

		if(!$sql){ 
    echo 'There has been an error creating your account. Please contact the webmaster.'; 
    echo mysql_error();
} else { 
    echo 'E-Mail updated! This is your new login, so remember it! '.$email_address.''; 
}
So you just have to say on the update, that if email address is existing and email address is NOT this users address, throw the error.. otherwise update.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

and thats what im asking how to do.....

you cant just type value1check and value2check
Post Reply