Page 1 of 2
EMail address changes
Posted: Sat Aug 19, 2006 12:32 am
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();
}
Posted: Sat Aug 19, 2006 12:38 am
by feyd
Make the column unique and you won't be able to update the record to an existing one.
Posted: Sat Aug 19, 2006 12:55 am
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.
Posted: Sat Aug 19, 2006 6:50 am
by Ollie Saunders
4Boredom where did you learn to do that?:
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.
Posted: Sat Aug 19, 2006 10:23 am
by RobertGonzalez
Posted: Sun Aug 20, 2006 8:59 pm
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
Posted: Sun Aug 20, 2006 9:07 pm
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.
Posted: Sun Aug 20, 2006 9:18 pm
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?
Posted: Sun Aug 20, 2006 9:20 pm
by feyd
Where $me is their user ID.
Posted: Sun Aug 20, 2006 11:07 pm
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(); }
Posted: Sun Aug 20, 2006 11:08 pm
by RobertGonzalez
Are you inserting or updating? And what is triggering that message.
Posted: Sun Aug 20, 2006 11:16 pm
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...
Posted: Sun Aug 20, 2006 11:21 pm
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.'';
}
Posted: Sun Aug 20, 2006 11:28 pm
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.
Posted: Sun Aug 20, 2006 11:53 pm
by 4Boredom
and thats what im asking how to do.....
you cant just type value1check and value2check