PHP Check if User is already registered : <p>I have an issue with my code to check if a username is already registered. I did a search on here to look at the different solutions and implemented some of them on my code but I still can't seem to get it to work. I tried registering the same username multiple times it still lets register without alerting me that the username is already taken. I apologize if this is easy to solve as I am new to php and mysql.</p>

<p>I tried multiple solutions but none seem to work for me. This is my latest iteration of my code.</p>

<pre><code>&lt;?php
session_start();

if (isset($_POST['submit'])) {

    $dbCon = mysqli_connect("localhost", "root", "badassrichv", "FootballDB");

    if (mysqli_connect_errno()) {
    echo "Failed to connect: " . mysqli_connect_error();
    }

    $username = strip_tags($_POST['name']);
    $password = strip_tags($_POST['password']);
    $email = strip_tags($_POST['email']);

$checkName = 'SELECT * FROM user WHERE username = "$username"';
$run = mysqli_query($dbCon, $checkName);
$data = mysqli_fetch_array($run, MYSQLI_NUM);

if ($data[0] &gt; 0) {
    echo "&lt;script&gt;alert('Name already registered. Input a different name')&lt;/script&gt;";
    exit();

} else {

$sql = "INSERT INTO user (username, password, email) VALUES ('$username', '$password', '$email')";

}

....More code
</code></pre>
