blacktiger786 Posted November 1, 2013 Share Posted November 1, 2013 <?php require 'databaseconnect.php'; if(isset($_POST['username'])) { $username=$_POST['username']; $query="SELECT `username` FROM `user` WHERE `username`='$username'"; if($run=mysql_query($query)) { if(mysql_num_rows($run)==1) { echo 'user already exist'; } else { echo'its fine'; } } } ?> <form method="post" action="11.php"> <input name="username" type="text"/><br> <input name="submit" type="submit"/> </form> like i enter blacktiger this user already in my database but when i click on button its show its fine echo run .. why is not run user already exist.. Quote Link to comment Share on other sites More sharing options...
alpine Posted November 1, 2013 Share Posted November 1, 2013 I would check that there is none with that username, if you have 2 or more already stored while comparing with "1", it will always allow yet another one. if(mysql_num_rows($run) === 0){ echo 'nobody with that username was found in database'; } else{ echo 'You cannot use this username'; } Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 4, 2013 Share Posted November 4, 2013 You should also consider using the LIMIT clause so that MySQL doesn't keep looking through the database when a match is found. $query="SELECT `username` FROM `user` WHERE `username`='$username' LIMIT 1"; Quote Link to comment 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.