<div class="form-group">  
    <label class="col-sm-4 control-label" for="user">Username :</label>
      <div class="col-sm-6">  
        <input type="text" name="username" id="username" class="form-control" required onclick="cek(document.getElementById('username'), this);">  
      </div>
  </div>
  <script> 
function cek(user)  
{ 
    <?php 
    $n = $_GET['username'])) 
 
    $query = "SELECT username from user where username ='$n'";
    $result= mysqli_query($link, $query); 
    while ($data= mysqli_fetch_array($result,MYSQLI_BOTH)) 
      { 
        $p= $data['username']; 
        echo "if (username.value == \"".$p."\")"; 
        echo "{"; 
        echo "username.setCustomValidity('usernamesudah ada')"; 
        echo "} else {"; 
        echo "username.setCustomValidity('')"; 
        echo "}"; 
      } 
    } 
      ?> 
} 
</script>

dari code diatas apakah ada yang salah atau kurang ya, mohon pencerahannya,:)
Silahkan login untuk menjawab!