i trying implement registration form web app. once insert 'name' , 'email' provided user database (mysql). need separate error messages pop on registration form if 'name' or 'email' in use,
"the 'name' in use"
or
"the 'email' in use"
the problem use error mysql show message
"the 'name' or 'email' in use"
my question how can use mysql error distinguish whether 'name' or 'email' being duplicated.
app.post(myargs[0]+"/register", function(req,res){ con.query('insert users values(uuid(),\'' + req.body.user + '\',\''+req.body.pass+'\',\''+req.body.mail+'\',null)',function(err,res){ if(err){ console.error(err+" ooops name or email in use !"); //here want find out whether name or email in use! errorregister(); return; } else { passregister(); } }) function errorregister(){ res.redirect(myargs[0]+"/register"); console.log(_dict); } function passregister(){ res.redirect(myargs[0]+"/login"); console.log(_dict); } });
after db give error on inserting, know either email
or name
, or both, duplicated.
you can search db name
, email
.
after that, customizing error message easy.
checking before inserting go wrong in case of race conditions (two users trying register same name/email @ same time). after inserting, know sure duplicated.
Comments
Post a Comment