any one know how to do this
Started on the old forum in May 2009 · view the original in the archive · old links redirect here
jsyguy23 wrote: does any one know how to let an email addy only reg with one username like you cant reg the same username 2 times lol i been trying to do it but got no where
$usercheck="SELECT*from users where username='$username' or email='$email'";
$usercheck2=mysql_query($usercheck);
while ($usercheck3=mysql_fetch_array($usercheck2))
{
$valid=0;
}
if($valid==0)
{
print "That username has been taken or there is already someone registered with that email, please <A href='register.php'>Try to register again</a>.";
}
better way would be to create a unique key on the email or username field then when u try and dupe a user it wont work, then its just a case of using a bit of code to grab the error number, and if the error code is 1062 (i think would have to check) then its a dupe entry and you can display error accordingly
simply removes the need for that code block, makes the code nicer, allows for multiple things to be checked in one go using error codes and correct setup of tables and more importantly reduces number of queries