0

Hey guys I have a table called username, and in my programm i have the possibility to create new users with an username and a password.

But I dont want to have two users with the same username

Im using php and mysql.

How can I handle this?

thx nubu

John Woo
  • 249,283
  • 65
  • 481
  • 481
Nubu
  • 29
  • 3

2 Answers2

0

add UNIQUE constraint so to enforce distinct values on the column,

ALTER TABLE tableNAme ADD CONSTRAINT tb_unique UNIQUE(username)
John Woo
  • 249,283
  • 65
  • 481
  • 481
0

You can check if the name already exists an ask the user to select a different name;

SELECT COUNT(username) FROM users WHERE userName = '[name to check]'

and add a unique index to the username field

splash21
  • 779
  • 4
  • 10
  • can i realize it in php and if yes how ... that i check every column and if the username is equals to my post ... its not possible to save this user? – Nubu Mar 11 '13 at 14:44