php
public function livecheck($check_value, $value){
global $connection;
$query = "SELECT * FROM users WHERE $check_value = ? LIMIT 1";
$results = $connection->select($query,$value);
//return total count
$results_exist = $results->rowCount();
$results_exist = $results->fetch();
//if value is more than 0, username is not available
if($results_exist) {
//out jquery echo
echo "We're sorry, that username is not available.";
//return fail change border to red
$_exist = true;
}else{
echo "username is available.";
//return true change border to grey
$_exist = false;
}
}
jquery
function checkusername(){
var username_value = $("#username").val();
if (username_value.length >= 4){
//checking the database username exits
// $("#user-result").html('<img src="imgs/ajax-loader.gif" />');
// post value isit using it self?//
$.post('class/validation.php', {'username':username_value}, function(data) {
$("#user-result").html(data);
// get the return data from php , fail = red , true = grey
$("#username").css(data);
});
}
return;
}
this is a live validation checking my database username and my intention is use jquery to change my css border color depends on my php return Boolean , i was able to echo the Boolean data ,so php check if username exists , border = red , else border = grey.
i hope i explain it right , i cant figure it out where to start this.