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!
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?
$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?
$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();
}
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.
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.
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.
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?
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!
$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(); }
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...
# 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.'';
}
# 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.