Add unique constraintto table:
alter table users
add unique (username)
Then your instructions insertor updatefail:
mysql_query("insert into users (username) values ('$username')")
or die('Username exists');
Of course, the big problem with your code is that you are not preventing SQL injection. Your code should be:
$username = mysql_real_escape_string($_POST['username']);
mysql_query("insert into users (username) values ('$username')")
or die('Username exists');
source
share