How can I check if a username already exists in a MySQLi row? : <p>This is my database
<a href="https://i.stack.imgur.com/D1rF8.png" rel="nofollow noreferrer">Database img</a></p>

<p>Imagine the blurred text is simply "test". </p>

<p>I have a basic login/signup form which inserts their data into a database. I want to make sure you can't have 2 users with the same email address, I've tried the following code, but for some reasons, it ignores this and just lets me create an account with the same email. How would I edit this code to make it show an error if you pick an email that someone else has used? Any help is appreciated.</p>

<pre><code>$exist = mysqli_query($conn, "SELECT * FROM username WHERE username='".$username."'");

if(mysqli_num_rows($exist) &gt; 0){
    die("email already exists");
}
</code></pre>

<p>Here is my <code>$conn</code>.<br>
<code>$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);</code></p>

<p>The connection to the DB works fine.</p>
