SJames Posted September 2, 2007 Share Posted September 2, 2007 I am trying to make a system that detects wherther an entry has been made in the database containing a certain value. More accurately, the system checks the database of usernames to see if the username the user entered in the sign up page has been used. If not, it allows the name to be used, if so, it does not allow it to be used. The database stores the information in the cells: username, password, and userID (an auto-incrementing cell) The database is called usernames. What I am asking for is the code I would use to do the username check. Basically: if (username has been used) { don't allow user to sign up, and present an error message } else { allow user to sign up, and complete the registration process } Quote Link to comment https://forums.phpfreaks.com/topic/67693-solved-mysql-detect-values/ Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Simply query the database beforehand. Assuming the username the user typed is contained within $_POST['uname'].... <?php // connect to db. if ($result = mysql_query("SELECT uname FROM users WHERE uname = '{$_POST['uname']}'")) { if (mysql_num_rows($result)) { // username already exists. } else { // do INSERT query for new user. } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67693-solved-mysql-detect-values/#findComment-340063 Share on other sites More sharing options...
SJames Posted September 2, 2007 Author Share Posted September 2, 2007 That's perfect. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/67693-solved-mysql-detect-values/#findComment-340064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.