PHP Login application - Check if username already exists when creating a new user <p>The title tells pretty much everthing, that needs to be said. I'm having a registration code looking like this: </p> <p>I wan't it to check, if the username entered already exists, if it does - write and $errMsg = ""; and echo it out later.. I hope you can help me, thanks. </p> <pre><code>if(isset($_POST['username']) &amp;&amp; isset($_POST['password']) &amp;&amp; isset($_POST['name']) &amp;&amp; isset($_POST['last_name']) &amp;&amp; isset($_POST['company'])){ if($username === '') { $errMsg = "Du skal udfylde brugernavn"; } elseif($password === ''){ $errMsg = "Du skal udfylde password"; } elseif($name === ''){ $errMsg = "Du skal udfylde navn"; } elseif($last_name === ''){ $errMsg = "Du skal udfylde efternavn"; } elseif($company === ''){ $errMsg = "Du skal udfylde firma"; } $sql = ("SELECT * FROM members WHERE username ='$username'"); $result = mysql_query($sql) or die('error'); $row = mysql_fetch_assoc($result); if(mysql_num_rows($result)) { $errMsg = 'Brugernavn findes, vælg et andet.'; } else { $sql = ("INSERT INTO members (username, password, name, last_name, company, salt)VALUES('$username', '$password', '$name', '$last_name', '$company', '$salt')")or die(mysql_error()); if(mysql_query($sql)) echo "Du er oprettet som profil."; } }//End whole if </code></pre>