Forum Moderators: coopster

Message Too Old, No Replies

Management of users accounts? How

         

toplisek

9:16 am on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello,
I have many fields like country, phone, street. How to do validation control if e-mail can be just one in database? Example is: User has its account page. He can not change username but he changes his e-mail. Current control will detect in db that there is already used e-mail (he is registered under this e-mail value). So if he would like not to change e-mail, he will have all the time error notification e-mail is already in use.

But this control should be because e-mail should be used only once in db. is this correct?

henry0

12:20 pm on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



toplisek,
Welcome to WebmasterWorld!

Not sure I got you loud and clear
anyway if the username or email or username associated with eamil are used as a form of authentication

A user could be allowed to enter a modification upon posting his/her username and email
as such it should be considered as a pair
and that pair as a pair (username and email) needs to be the new username and passord
its an update not an isert therefore not a duplicate

justgowithit

4:34 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



I think I see what you're getting at here. Here's what I would do. Maybe it will help. I'd first load the existing user email into a session before the edit form is presented by piggy-backing another db query to minimize overhead. Then I'd create the edit form that posts back to itself and......

if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', trim($_POST['email']))) {//check input
$e = $_POST['email'];

if ($e!== $_SESSION['email']){ // if the email address was changed check it's availability now

$query = "SELECT anyColumn FROM table WHERE email='$e'";

$result = mysql_query($query) or trigger_error ("my error");

if (mysql_affected_rows() == 1) {

echo 'This email address is already registered. Please use another email address.';
}

}

} else { //validation failed
echo 'Please provide your email.';
}

Then if the email session variable is no longer needed I'd unset it.