I don't know whats wrong but my code not working properly
here is my html code
<input type="text" name="username" id="username">
<div id="check_usr"></div>
AJAX call
<script>
$(document).ready(function() { //user name
$('#username').on("keypress", function(e)
{
startTypingTimer($(e.target));
});
});
var typingTimeout;
function startTypingTimer(input_field)
{
if (typingTimeout != undefined)
clearTimeout(typingTimeout);
typingTimeout = setTimeout( function()
{
if($('#username').val().length < 4 ){
$('#check_usr').empty().append('<span class="label label-important">Username must be more than 3 charachters</span>');
}else {
$.ajax({
url: "checkuser.php",
type: 'POST',
data : {username : $('#username').val()},
success:function(data){
if(data === 'yes'){
$('#check_usr').empty().append('<span class="label label-warning">Username is already taken</span>');
}else{
$('#check_usr').empty().append('<span class="label label-success">OK</span>');
}
}});
}
}
, 500);
}
</script>
and php file
<?php
include ('config.php');
if ($_POST) {
$user = mysql_real_escape_string($_POST['username']);
$sql = "SELECT user FROM `users` WHERE `user` = '".$user."'";
$run = mysql_query($sql);
if ($run) {
return 'yes';
unset ($sql,$run,$user,$_POST);
}
}
?>
Every time I ran the code the text "OK" appears even if the user found in table
tell me whats wrong ?