I have a file where I put all my needed functions. The one that I need is this one:
//the functions file
//........
function user_exists($username){
$username = sanitize($username);
$query = mysql_query("SELECT COUNT('user_id') FROM users WHERE username = '$username'");
return (mysql_result($query, 0) == 1) ? true : false;
}
?>
I have included the functions file in my register.php file. What I want to do is call that function from javascript:
//the register file (functions file is included here)
<script>
//.....
if(user_exists(element.value)){ ........ }
//.....
</script>
I think this can be solved with ajax but how to do it exactly since I'm not familiar with it?