title: Check username already exist using mysqli and php (PhpMyAdmin)
body: <p>con.php</p>
  
  <pre><code>&lt;?php
  $_HOST="localhost";
  $_USER="root";
  $_PASS="";
  $_DBNM="test";
  
  $con=mysqli_connect($_HOST, $_USER, $_PASS, $_DBNM);
  
  if ($con === false)
  {
      die ("Database Connection Failed");
  }
  echo "Database Connection Succeed &lt;br&gt;";
  ?&gt;
  </code></pre>
  
  <p>register.php</p>
  
  <pre><code>&lt;?php
  include("con.php");
  $username=$_POST['username'];
  $password=$_POST['password'];
  $level=$_POST['level'];
  
  $sql = "select username from user where username='$username'";
  $data = mysqli_query($con,$sql);
  
  if(mysqli_num_rows($data) &gt; 0)
  {   
      echo '&lt;script language="JavaScript"&gt;alert("Username Already Exist!");
          document.location:"register.html"&lt;/script&gt;';
  }
  else
  {
      $query = $con-&gt;query("INSERT INTO user (username, password, level) 
          VALUES ('$username', '$password', '$level')");
      echo '&lt;script language="JavaScript"&gt;alert("Registration Succeed!");
      document.location:"index.php"&lt;/script&gt;';
  }
  
  ?&gt;
  </code></pre>
  
  <p>so the code is working for not inserting account if the username already exist, but it doesn't show the echo and it got stuck on the con.php.
  Also, When I enter the non-exist username, the account added successfully but the echo didn't apppear.</p>