rallokkcaz Posted May 2, 2007 Share Posted May 2, 2007 in my registration form i want it so you can't register if someone else has the same user name i don't know how i forgot this help would be nice Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/ Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Simply run a SELECT statement against your database, if the username already exists, don't allow the user to be added. Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/#findComment-243048 Share on other sites More sharing options...
clown[NOR] Posted May 2, 2007 Share Posted May 2, 2007 $query = "SELECT * FROM `database` WHERE username = '".$username."' LIMIT 1"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } $rows = mysql_num_rows($result); if ($rows > 0) { echo "user allready exists"; } else { echo "user don't exist"; } Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/#findComment-243051 Share on other sites More sharing options...
rallokkcaz Posted May 2, 2007 Author Share Posted May 2, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/#findComment-243055 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 link=topic=138756.msg588491#msg588491 date=1178068730] $query = "SELECT * FROM `database` WHERE username = '".$username."' LIMIT 1"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } $rows = mysql_num_rows($result); if ($rows > 0) { echo "user allready exists"; } else { echo "user don't exist"; } I'm sorry, but that is a terrible example of how to code. Its hardly friendly on the eye. <?php $query = "SELECT * FROM database WHERE username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { // user already exists. } else { // do the signup, INSERT. } } else { // query failed, handle error / debugging. } ?> Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/#findComment-243058 Share on other sites More sharing options...
clown[NOR] Posted May 2, 2007 Share Posted May 2, 2007 hehe... don't think I code like that normally... that was jsut quicky written here... the person needs to figure out himself how he want's to set it up to make it easier to read... Link to comment https://forums.phpfreaks.com/topic/49576-solved-major-noob-question/#findComment-243061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.