MySql Unique Index how to generate appropriate Response? -


i have simple database contains table users of game. want user names , email addresses unique, have set them have unique index.

whenever new user register game, statement executed:

tmpquery = "insert vertix_users (user_name, user_email, user_pass) " +     "values (" + mysql.escape(username) +     ", " + mysql.escape(useremail) +      ", " + mysql.escape(userpass) + ") " +     "on duplicate key " +     "return 'this username exists'"; 

i can simple insert ignore avoid duplicate user names or email addresses. do, generate useful feedback user; "this name has been taken." or "email in use". code above arbitrary example of thought work. how can achieve along lines?

i think simplest solution run previous query check whether name exists. registering process not demanding process, since every user registers once. don't think worth try in 1 query. besides, separate "checkusername" process, can check it, if want, before registration form sent server. example, user finishes write desired username.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -